mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
improve api
This commit is contained in:
37
plugins/scm-hg-plugin/src/main/java/sonia/scm/HgPlugin.java
Normal file
37
plugins/scm-hg-plugin/src/main/java/sonia/scm/HgPlugin.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class HgPlugin extends ScmWebPluginAdapter
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String SCRIPT = "/sonia/scm/hg.config.js";
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public InputStream getScript()
|
||||
{
|
||||
return HgPlugin.class.getResourceAsStream(SCRIPT);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.api.rest.resources;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Singleton
|
||||
@Path("config/repositories/hg")
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public class HgConfigResource
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param repositoryManager
|
||||
*/
|
||||
@Inject
|
||||
public HgConfigResource(RepositoryManager repositoryManager)
|
||||
{
|
||||
handler = (HgRepositoryHandler) repositoryManager.getHandler(
|
||||
HgRepositoryHandler.TYPE_NAME);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GET
|
||||
public HgConfig getConfig()
|
||||
{
|
||||
return handler.getConfig();
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param uriInfo
|
||||
* @param config
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response setConfig(@Context UriInfo uriInfo, HgConfig config)
|
||||
{
|
||||
handler.setConfig(config);
|
||||
handler.storeConfig();
|
||||
|
||||
return Response.created(uriInfo.getRequestUri()).build();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private HgRepositoryHandler handler;
|
||||
}
|
||||
@@ -153,19 +153,19 @@ public class HgRepositoryHandler implements RepositoryHandler
|
||||
File baseDirectory = context.getBaseDirectory();
|
||||
|
||||
AssertUtil.assertIsNotNull(baseDirectory);
|
||||
configFile = new File(baseDirectory, CONFIG_FILE);
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
File configFile = new File(baseDirectory, CONFIG_FILE);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
public void loadConfig()
|
||||
{
|
||||
if (configFile.exists())
|
||||
{
|
||||
config = JAXB.unmarshal(configFile, HgConfig.class);
|
||||
|
||||
if (config.getConfigDirectory() == null)
|
||||
{
|
||||
File configDirectory = new File(baseDirectory, DEFAULT_CONFIGPATH);
|
||||
|
||||
config.setConfigDirectory(configDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,6 +213,15 @@ public class HgRepositoryHandler implements RepositoryHandler
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
public void storeConfig()
|
||||
{
|
||||
JAXB.marshal(config, configFile);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -285,6 +294,17 @@ public class HgRepositoryHandler implements RepositoryHandler
|
||||
return repositories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public HgConfig getConfig()
|
||||
{
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -309,6 +329,19 @@ public class HgRepositoryHandler implements RepositoryHandler
|
||||
return config != null;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param config
|
||||
*/
|
||||
public void setConfig(HgConfig config)
|
||||
{
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -501,4 +534,7 @@ public class HgRepositoryHandler implements RepositoryHandler
|
||||
|
||||
/** Field description */
|
||||
private HgConfig config;
|
||||
|
||||
/** Field description */
|
||||
private File configFile;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user