merge with branch 1.x

This commit is contained in:
Sebastian Sdorra
2014-06-04 15:51:19 +02:00
42 changed files with 1689 additions and 102 deletions

View File

@@ -277,6 +277,7 @@
<localCheckout>true</localCheckout>
<releaseProfiles>release,APIviz,doc</releaseProfiles>
<tagNameFormat>@{project.version}</tagNameFormat>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</plugin>

View File

@@ -22,7 +22,6 @@
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -107,6 +106,124 @@
</plugins>
</build>
<profiles>
<profile>
<id>it</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>sonia.scm</groupId>
<artifactId>scm-webapp</artifactId>
<version>${project.version}</version>
<type>war</type>
<outputDirectory>${project.build.directory}/webapp</outputDirectory>
<destFileName>scm-webapp.war</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12</version>
<configuration>
<systemPropertyVariables>
<scm.version>${project.version}</scm.version>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<stopPort>8085</stopPort>
<stopKey>STOP</stopKey>
<systemProperties>
<systemProperty>
<name>scm.home</name>
<value>target/scm-it</value>
</systemProperty>
<systemProperty>
<name>file.encoding</name>
<value>UTF-8</value>
</systemProperty>
</systemProperties>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8081</port>
<maxIdleTime>60000</maxIdleTime>
<requestHeaderSize>16384</requestHeaderSize>
</connector>
</connectors>
<webApp>
<contextPath>/scm</contextPath>
</webApp>
<war>${project.build.directory}/webapp/scm-webapp.war</war>
<source>${project.build.javaLevel}</source>
<target>${project.build.javaLevel}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy-war</goal>
</goals>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<repositories>
<repository>

View File

@@ -0,0 +1,129 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.cli;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.collect.Lists;
import com.google.common.io.Closeables;
//~--- JDK imports ------------------------------------------------------------
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
/**
*
* @author Sebastian Sdorra
*/
public abstract class AbstractITCaseBase
{
/**
* Method description
*
*
* @param cmd
*
* @return
*
* @throws IOException
*/
protected String execute(String... cmd) throws IOException
{
String result = null;
ByteArrayInputStream inputStream = null;
ByteArrayOutputStream outputStream = null;
try
{
inputStream = new ByteArrayInputStream(new byte[0]);
outputStream = new ByteArrayOutputStream();
App app = new App(inputStream, outputStream);
app.run(cmd);
outputStream.flush();
result = outputStream.toString().trim();
}
finally
{
Closeables.close(inputStream, true);
Closeables.close(outputStream, true);
}
return result;
}
/**
* Method description
*
*
* @param cmd
*
* @return
*
* @throws IOException
*/
protected String executeServer(String... cmd) throws IOException
{
List<String> cmdList = Lists.newArrayList();
cmdList.add("--server");
cmdList.add("http://localhost:8081/scm");
cmdList.add("--user");
cmdList.add("scmadmin");
cmdList.add("--password");
cmdList.add("scmadmin");
cmdList.addAll(Arrays.asList(cmd));
return execute(cmdList.toArray(new String[cmdList.size()]));
}
/**
* Method description
*
*
* @param values
*
* @return
*/
protected String prepareForTest(String values)
{
return values.replaceAll("\\n", ";").replaceAll("\\s+", "");
}
}

View File

@@ -0,0 +1,86 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.cli;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @author Sebastian Sdorra
*/
public class RepositoriesITCase extends AbstractITCaseBase
{
/**
* Method description
*
*
* @throws IOException
*/
@Test
public void listRepositoriesTest() throws IOException
{
executeServer("create-repository", "--type", "git", "--name", "hobbo",
"--description", "Test Repo");
String repositories = prepareForTest(executeServer("list-repositories"));
assertThat(repositories, containsString("Name:hobbo;"));
assertThat(repositories, containsString("Description:TestRepo;"));
assertThat(repositories, containsString("Type:git;"));
Pattern pattern = Pattern.compile("ID:([^;]+);");
Matcher matcher = pattern.matcher(repositories);
if (!matcher.find())
{
fail("could not extract id of repository");
}
String id = matcher.group(1);
executeServer("delete-repository", id);
}
}

View File

@@ -0,0 +1,70 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.cli;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
/**
*
* @author Sebastian Sdorra
*/
public class ServerVersionITCase extends AbstractITCaseBase
{
/**
* Method description
*
*
* @throws IOException
*/
@Test
public void testServerVersion() throws IOException
{
String systemVersion = System.getProperty("scm.version");
assumeTrue("skip test, because system property scm.version is not set",
systemVersion != null);
String version = executeServer("server-version");
assertEquals("scm-manager version: ".concat(systemVersion), version);
}
}

View File

@@ -0,0 +1,72 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.cli;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
/**
*
* @author Sebastian Sdorra
*/
public class UsersITCase extends AbstractITCaseBase
{
/**
* Method description
*
*
* @throws IOException
*/
@Test
public void listUsersTest() throws IOException
{
String users = prepareForTest(executeServer("list-users"));
assertThat(users, containsString("Name:scmadmin;"));
assertThat(users, containsString("DisplayName:SCMAdministrator;"));
assertThat(users, containsString("Type:xml;"));
assertThat(users, containsString("E-Mail:scm-admin@scm-manager.org;"));
assertThat(users, containsString("Active:true;"));
assertThat(users, containsString("Administrator:true;"));
System.out.println(users);
}
}

View File

@@ -0,0 +1,65 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.cli;
//~--- non-JDK imports --------------------------------------------------------
import org.junit.Test;
import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
/**
*
* @author Sebastian Sdorra
*/
public class VersionITCase extends AbstractITCaseBase
{
/**
* Method description
*
*
* @throws IOException
*/
@Test
public void testVersion() throws IOException
{
// maven properties are not available during it tests
String version = execute("version");
assertEquals("scm-cli-client version: unknown", version);
}
}

View File

@@ -70,7 +70,7 @@ public abstract class DirectoryHealthCheck implements HealthCheck
private static final HealthCheckFailure DIRECTORY_DOES_NOT_EXISTS =
new HealthCheckFailure("1oOTx803F1",
"repository directory does not exists",
"The repository does not exists. Perhaps it was deleted outside of scm-manafer.");
"The repository does not exists. Perhaps it was deleted outside of scm-manager.");
/**
* the logger for DirectoryHealthCheck

View File

@@ -35,6 +35,8 @@ package sonia.scm.security;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.annotations.VisibleForTesting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -106,6 +108,21 @@ public class DefaultCipherHandler implements CipherHandler
//~--- constructors ---------------------------------------------------------
/**
* Constructs a new DefaultCipherHandler. Note this constructor is only for
* unit tests.
*
*
* @param key
*
* @since 1.38
*/
@VisibleForTesting
protected DefaultCipherHandler(String key)
{
this.key = key.toCharArray();
}
/**
* Constructs ...
*
@@ -116,7 +133,7 @@ public class DefaultCipherHandler implements CipherHandler
*
*/
public DefaultCipherHandler(SCMContextProvider context,
KeyGenerator keyGenerator)
KeyGenerator keyGenerator)
{
File configDirectory = new File(context.getBaseDirectory(), "config");
@@ -178,7 +195,7 @@ public class DefaultCipherHandler implements CipherHandler
System.arraycopy(encodedInput, 0, salt, 0, SALT_LENGTH);
System.arraycopy(encodedInput, SALT_LENGTH, encoded, 0,
encodedInput.length - SALT_LENGTH);
encodedInput.length - SALT_LENGTH);
IvParameterSpec iv = new IvParameterSpec(salt);
SecretKey secretKey = buildSecretKey(plainKey);
@@ -245,7 +262,7 @@ public class DefaultCipherHandler implements CipherHandler
System.arraycopy(salt, 0, result, 0, SALT_LENGTH);
System.arraycopy(encodedInput, 0, result, SALT_LENGTH,
result.length - SALT_LENGTH);
result.length - SALT_LENGTH);
res = new String(Base64.encode(result), ENCODING);
}
catch (Exception ex)
@@ -270,7 +287,7 @@ public class DefaultCipherHandler implements CipherHandler
* @throws UnsupportedEncodingException
*/
private SecretKey buildSecretKey(char[] plainKey)
throws UnsupportedEncodingException, NoSuchAlgorithmException
throws UnsupportedEncodingException, NoSuchAlgorithmException
{
byte[] raw = new String(plainKey).getBytes(ENCODING);
MessageDigest digest = MessageDigest.getInstance(DIGEST_TYPE);

View File

@@ -37,7 +37,6 @@ package sonia.scm.util;
import com.google.common.base.CharMatcher;
import com.google.common.base.Strings;
import com.google.common.io.ByteStreams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@@ -34,6 +34,7 @@ package sonia.scm.xml;
//~--- JDK imports ------------------------------------------------------------
import com.google.common.annotations.VisibleForTesting;
import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
@@ -48,7 +49,8 @@ public final class IndentXMLStreamWriter implements XMLStreamWriter
{
/** line separator */
private static final String LINE_SEPARATOR =
@VisibleForTesting
static final String LINE_SEPARATOR =
System.getProperty("line.separator");
//~--- constructors ---------------------------------------------------------

View File

@@ -86,15 +86,14 @@ public class IndentXMLStreamWriterTest
String content = baos.toString();
//J-
Assert.assertEquals(
"<?xml version=\"1.0\" ?>\n" +
"<root>\n" +
" <message>Hello</message>\n" +
"</root>\n",
content
);
//J
StringBuilder buffer = new StringBuilder("<?xml version=\"1.0\" ?>");
buffer.append(IndentXMLStreamWriter.LINE_SEPARATOR);
buffer.append("<root>").append(IndentXMLStreamWriter.LINE_SEPARATOR);
buffer.append(" <message>Hello</message>");
buffer.append(IndentXMLStreamWriter.LINE_SEPARATOR);
buffer.append("</root>").append(IndentXMLStreamWriter.LINE_SEPARATOR);
Assert.assertEquals(buffer.toString(), content);
}

View File

@@ -0,0 +1,135 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import sonia.scm.plugin.Extension;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
/**
* Simple {@link HealthCheck} for git repositories.
*
* @author Sebastian Sdorra
* @since 1.39
*/
@Extension
public final class GitHealthCheck extends DirectoryHealthCheck
{
/** Field description */
private static final HealthCheckFailure COULD_NOT_FIND_GIT_DIRECTORIES =
new HealthCheckFailure("AKOdhQ0pw1",
"Could not find .git or refs directory",
"The git repository does not contain a .git or a refs directory.");
/** Field description */
private static final String DIRECTORY_DOT_GIT = ".git";
/** Field description */
private static final String DIRECTORY_REFS = "refs";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param repositoryManager
*/
@Inject
public GitHealthCheck(RepositoryManager repositoryManager)
{
super(repositoryManager);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param repository
* @param directory
*
* @return
*/
@Override
protected HealthCheckResult check(Repository repository, File directory)
{
HealthCheckResult result = HealthCheckResult.healthy();
if (!isGitRepository(directory))
{
result = HealthCheckResult.unhealthy(COULD_NOT_FIND_GIT_DIRECTORIES);
}
return result;
}
//~--- get methods ----------------------------------------------------------
/**
* Returns {@code true} if the repository is from type git.
*
*
* @param repository repository for the health check
*
* @return {@code true} for a mercurial git
*/
@Override
protected boolean isCheckResponsible(Repository repository)
{
return GitRepositoryHandler.TYPE_NAME.equalsIgnoreCase(
repository.getType());
}
/**
* Returns {@code true} if the directory contains a .git directory or a refs
* directory (bare git repository).
*
*
* @param directory git repository directory
*
* @return {@code true} if the directory contains a git repository
*/
private boolean isGitRepository(File directory)
{
return new File(directory, DIRECTORY_DOT_GIT).exists()
|| new File(directory, DIRECTORY_REFS).exists();
}
}

View File

@@ -36,7 +36,6 @@ package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
@@ -44,8 +43,6 @@ import org.eclipse.jgit.api.FetchCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.diff.DiffFormatter;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
@@ -68,7 +65,6 @@ import sonia.scm.util.Util;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@@ -471,9 +467,6 @@ public final class GitUtil
*
* @return
*
* @throws IncorrectObjectTypeException
* @throws MissingObjectException
*
* @throws IOException
*/
public static Ref getRefForCommit(org.eclipse.jgit.lib.Repository repository,

View File

@@ -85,7 +85,7 @@ public class GitRepositoryViewer
public static final String MIMETYPE_HTML = "text/html";
/** Field description */
public static final String RESOURCE_GITINDEX = "sonia/scm/git.index.mustache";
public static final String RESOURCE_GITINDEX = "/sonia/scm/git.index.mustache";
/** Field description */
private static final int CHANGESET_PER_BRANCH = 10;

View File

@@ -35,7 +35,6 @@ package sonia.scm.installer;
//~--- non-JDK imports --------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@@ -0,0 +1,116 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.repository;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import sonia.scm.plugin.Extension;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
/**
* Simple {@link HealthCheck} for mercurial repositories.
*
* @author Sebastian Sdorra
* @since 1.39
*/
@Extension
public final class HgHealthCheck extends DirectoryHealthCheck
{
/** Field description */
private static final HealthCheckFailure COULD_NOT_FIND_DOT_HG_DIRECTORY =
new HealthCheckFailure("6bOdhOXpB1", "Could not find .hg directory",
"The mercurial repository does not contain .hg directory.");
/** Field description */
private static final String DOT_HG = ".hg";
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param repositoryManager
*/
@Inject
public HgHealthCheck(RepositoryManager repositoryManager)
{
super(repositoryManager);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param repository
* @param directory
*
* @return
*/
@Override
protected HealthCheckResult check(Repository repository, File directory)
{
HealthCheckResult result = HealthCheckResult.healthy();
File dotHgDirectory = new File(directory, DOT_HG);
if (!dotHgDirectory.exists())
{
result = HealthCheckResult.unhealthy(COULD_NOT_FIND_DOT_HG_DIRECTORY);
}
return result;
}
//~--- get methods ----------------------------------------------------------
/**
* Returns {@code true} if the repository is from type mercurial.
*
*
* @param repository repository for the health check
*
* @return {@code true} for a mercurial repository
*/
@Override
protected boolean isCheckResponsible(Repository repository)
{
return HgRepositoryHandler.TYPE_NAME.equalsIgnoreCase(repository.getType());
}
}

View File

@@ -42,7 +42,6 @@ import sonia.scm.plugin.Extension;
import sonia.scm.repository.HgContext;
import sonia.scm.repository.HgContextProvider;
import sonia.scm.repository.HgHookManager;
import sonia.scm.web.filter.BasicAuthenticationFilter;
/**
*

View File

@@ -40,7 +40,6 @@ import com.google.common.io.Closeables;
import sonia.scm.repository.Repository;
import sonia.scm.repository.SvnRepositoryHandler;
import sonia.scm.repository.SvnUtil;
import sonia.scm.repository.api.Command;
//~--- JDK imports ------------------------------------------------------------

View File

@@ -78,7 +78,7 @@ public class SvnCollectionRenderer implements CollectionRenderer
/** Field description */
private static final String RESOURCE_SVNINDEX =
"sonia/scm/svn.index.mustache";
"/sonia/scm/svn.index.mustache";
/**
* the logger for SvnCollectionRenderer

View File

@@ -75,7 +75,7 @@ public class SvnServletModule extends ServletModule
Map<String, String> parameters = new HashMap<String, String>();
parameters.put(PARAMETER_SVN_PARENTPATH,
System.getProperty("java.io.tmpdir"));
System.getProperty("java.io.tmpdir"));
serve(PATTERN_SVN).with(SvnDAVServlet.class, parameters);
}
}

View File

@@ -20,7 +20,7 @@
<dependency>
<groupId>commons-daemon</groupId>
<artifactId>commons-daemon</artifactId>
<version>1.0.10</version>
<version>${commons.daemon.version}</version>
</dependency>
<dependency>
@@ -56,7 +56,7 @@
<plugin>
<groupId>sonia.maven</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.2.0.3</version>
<version>1.2.2.0</version>
<executions>
<execution>
<id>scm-app</id>
@@ -67,7 +67,7 @@
</goals>
<configuration>
<target>${project.build.directory}/appassembler</target>
<assembleDirectory>${project.build.directory}/appassembler/commons-daemon/scm-server</assembleDirectory>
<assembleDirectory>${exploded.directory}</assembleDirectory>
<repoPath>lib</repoPath>
<repositoryLayout>flat</repositoryLayout>
<includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
@@ -75,7 +75,7 @@
<daemon>
<id>scm-server</id>
<version>1.0.10</version>
<version>${commons.daemon.version}</version>
<mainClass>sonia.scm.server.ScmServerDaemon</mainClass>
<platforms>
<platform>commons-daemon</platform>
@@ -101,6 +101,10 @@
<name>darwin.arch.enable</name>
<value>false</value>
</property>
<property>
<name>windows.service.dependencies</name>
<value>Tcpip</value>
</property>
</configuration>
</generatorConfiguration>
@@ -131,7 +135,7 @@
<artifactId>scm-webapp</artifactId>
<version>${project.version}</version>
<type>war</type>
<outputDirectory>${project.build.directory}/appassembler/commons-daemon/scm-server/var/webapp</outputDirectory>
<outputDirectory>${exploded.directory}/var/webapp</outputDirectory>
<destFileName>scm-webapp.war</destFileName>
</artifactItem>
</artifactItems>
@@ -163,5 +167,138 @@
<finalName>scm-server</finalName>
</build>
<profiles>
<profile>
<id>nativepkg</id>
<build>
<plugins>
<plugin>
<groupId>com.github.sdorra</groupId>
<artifactId>nativepkg-maven-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>deb</goal>
<goal>rpm</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
<configuration>
<attach>true</attach>
<classifier>all</classifier>
<release>${maven.build.timestamp}</release>
<section>devel</section>
<group>Development/Tools</group>
<vendor>SCM-Manager</vendor>
<license>BSD 3-Clause</license>
<url>www.scm-manager.org</url>
<summary>${project.description}</summary>
<packager>Sebastian Sdorra &lt;s.sdorra@gmail.com&gt;</packager>
<platform>
<architecture>noarch</architecture>
<os>linux</os>
</platform>
<scripts>
<preInstall>${project.basedir}/src/main/nativepkg/create-user</preInstall>
</scripts>
<mappings>
<files>
<file>
<path>/opt/scm-server/bin/scm-server</path>
<source>${exploded.directory}/bin/scm-server</source>
<mode>0744</mode>
</file>
<file>
<path>/opt/scm-server/conf/server-config.xml</path>
<source>${project.basedir}/src/main/conf/server-config.xml</source>
<config>true</config>
</file>
<file>
<path>/opt/scm-server/conf/logging.xml</path>
<source>${project.basedir}/src/main/nativepkg/logging.xml</source>
<config>true</config>
</file>
<file>
<path>/opt/scm-server/libexec/jsvc-linux-i686</path>
<source>${exploded.directory}/libexec/jsvc-linux-i686</source>
<mode>0744</mode>
</file>
<file>
<path>/opt/scm-server/libexec/jsvc-linux-x86_64</path>
<source>${exploded.directory}/libexec/jsvc-linux-x86_64</source>
<mode>0744</mode>
</file>
<file>
<path>/opt/scm-server/var/webapp/scm-webapp.war</path>
<source>${exploded.directory}/var/webapp/scm-webapp.war</source>
</file>
<file>
<path>/opt/scm-server/var/webapp/docroot/index.html</path>
<source>${basedir}/src/main/docroot/index.html</source>
</file>
<file>
<path>/etc/default/scm-server</path>
<source>${project.basedir}/src/main/nativepkg/default</source>
<mode>0744</mode>
<config>true</config>
</file>
<file>
<path>/etc/init.d/scm-server</path>
<source>${project.basedir}/src/main/nativepkg/init-script</source>
<mode>0744</mode>
</file>
</files>
<links>
<link>
<source>/opt/scm-server/var/log</source>
<target>/var/log/scm</target>
</link>
<link>
<source>/opt/scm-server/work</source>
<target>/var/cache/scm/work</target>
</link>
</links>
<directories>
<directory>
<path>/opt/scm-server/lib</path>
<source>${exploded.directory}/lib</source>
</directory>
<directory>
<path>/var/cache/scm/work</path>
<uname>scm</uname>
<gname>scm</gname>
<dirMode>0700</dirMode>
</directory>
<directory>
<path>/var/log/scm</path>
<uname>scm</uname>
<gname>scm</gname>
<dirMode>0770</dirMode>
</directory>
<directory>
<path>/var/lib/scm</path>
<uname>scm</uname>
<gname>scm</gname>
<dirMode>0700</dirMode>
</directory>
</directories>
</mappings>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties>
<commons.daemon.version>1.0.15</commons.daemon.version>
<exploded.directory>${project.build.directory}/appassembler/commons-daemon/scm-server</exploded.directory>
</properties>
</project>

View File

@@ -92,12 +92,23 @@ public class ScmServer extends Thread
{
try
{
server.start();
if (!initialized)
{
init();
}
server.join();
}
catch (Exception ex)
{
throw new RuntimeException(ex);
if (ex instanceof ScmServerException)
{
throw(ScmServerException) ex;
}
else
{
throw new ScmServerException("could not start scm-server", ex);
}
}
}
@@ -110,6 +121,7 @@ public class ScmServer extends Thread
try
{
server.setStopAtShutdown(true);
initialized = false;
}
catch (Exception ex)
{
@@ -117,8 +129,28 @@ public class ScmServer extends Thread
}
}
/**
* Method description
*
*/
void init()
{
try
{
server.start();
initialized = true;
}
catch (Exception ex)
{
throw new ScmServerException("could not initialize server", ex);
}
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private boolean initialized = false;
/** Field description */
private Server server = new Server();
}

View File

@@ -113,6 +113,9 @@ public class ScmServerDaemon implements Daemon
public void init(DaemonContext context) throws DaemonInitException, Exception
{
daemonArgs = context.getArguments();
// initialize web server and open port. We have to do this in the init
// method, because this method is started by jsvc with super user privileges.
webserver.init();
}
/**

View File

@@ -0,0 +1,5 @@
getent group scm >/dev/null || groupadd -r scm
getent passwd scm >/dev/null || \
useradd -r -g scm -M -s /sbin/nologin \
-c "user for the scm-server process" scm
exit 0

View File

@@ -0,0 +1,54 @@
#!/bin/sh
#
# Copyright (c) 2010, Sebastian Sdorra
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# 3. Neither the name of SCM-Manager; nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# http://bitbucket.org/sdorra/scm-manager
#
# scm-server port
PORT=8080
# change user
USER=scm
# home of scm-manager
export SCM_HOME=/var/lib/scm
# force jvm path
# JAVA_HOME="/usr/lib/jvm/jre"
# path to pid
PIDFILE=/var/run/scm.pid
# path to log directory
LOGDIR=/var/log/scm
# increase memory
# EXTRA_JVM_ARGUMENTS="$EXTRA_JVM_ARGUMENTS -Xms1g -Xmx1g"
# pass extra jvm arguments
EXTRA_JVM_ARGUMENTS="$EXTRA_JVM_ARGUMENTS -Djetty.port=$PORT"

View File

@@ -0,0 +1,118 @@
#!/bin/sh
#
# SCM-Server start script
#
#
# Copyright (c) 2010, Sebastian Sdorra
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# 3. Neither the name of SCM-Manager; nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# http://bitbucket.org/sdorra/scm-manager
#
# chkconfig: 35 35 65
# description: SCM-Server
#
### BEGIN INIT INFO
# Provides: scm-server
# Required-Start: $local_fs $remote_fs $network $time $named
# Required-Stop: $local_fs $remote_fs $network $time $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: SCM-Server
### END INIT INFO
# start script is based on the one posted from JavaNode to SCM-Manager mailing
# list: https://groups.google.com/d/msg/scmmanager/-wNjenUbl0Q/CkELJ6fLMHsJ
# Source function library.
if [ -x /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
fi
# Check for and source configuration file otherwise set defaults
RETVAL=0
appname=ScmServerDaemon
# See how we were called.
start() {
/opt/scm-server/bin/scm-server start
}
stop() {
if [ ! status = 0 ]
then
/opt/scm-server/bin/scm-server stop
else
echo "SCM-Server is not running"
fi
}
status() {
ps auxwww | grep java | grep ${appname} || echo "SCM-Server is not running"
}
restart() {
stop
SECONDS=0
STAT=$( ps auxwww | grep java | grep ${appname} | wc -l )
while [ $STAT -ne 0 ]
do
sleep 3
if [ $SECONDS -gt 300 ]
then
SCM_PID=$( ps auxwww | grep java | grep ${appname} | awk '{ print $2 }' )
kill -9 $SCM_PID
fi
STAT=$( ps auxwww | grep java | grep ${appname} | wc -l )
done
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $RETVAL

View File

@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2010, Sebastian Sdorra
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of SCM-Manager; nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
http://bitbucket.org/sdorra/scm-manager
-->
<!--
Document : logback.release.xml
Created on : May 9, 2014, 8:36 PM
Author : sdorra
Description:
Purpose of the document follows.
-->
<configuration>
<jmxConfigurator />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/var/log/scm/scm-manager.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>/var/log/scm/scm-manager-%i.log</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>10</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>10MB</maxFileSize>
</triggeringPolicy>
<append>true</append>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
<logger name="sonia.scm" level="INFO" />
<!-- suppress massive gzip logging -->
<logger name="sonia.scm.filter.GZipFilter" level="WARN" />
<logger name="sonia.scm.filter.GZipResponseStream" level="WARN" />
<logger name="sonia.scm.util.ServiceUtil" level="WARN" />
<!-- aether -->
<!--
<logger name="org.sonatype.aether" level="TRACE" />
<logger name="com.ning.http.client" level="DEBUG" />
-->
<!-- svnkit -->
<!--
<logger name="svnkit" level="WARN" />
<logger name="svnkit.network" level="DEBUG" />
<logger name="svnkit.fsfs" level="WARN" />
-->
<!-- javahg -->
<!--
<logger name="com.aragost.javahg" level="DEBUG" />
-->
<!-- ehcache -->
<!--
<logger name="net.sf.ehcache" level="DEBUG" />
-->
<root level="WARN">
<appender-ref ref="FILE" />
</root>
</configuration>

View File

@@ -0,0 +1,58 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.security;
//~--- JDK imports ------------------------------------------------------------
import java.util.UUID;
/**
* @author Sebastian Sdorra
* @since 1.38
*/
public class InMemoryCipherHandler extends DefaultCipherHandler
{
/** Field description */
private static final String KEY = UUID.randomUUID().toString();
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*/
public InMemoryCipherHandler()
{
super(KEY);
}
}

View File

@@ -0,0 +1 @@
sonia.scm.security.InMemoryCipherHandler

View File

@@ -173,7 +173,7 @@
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.1</version>
<version>1.9.2</version>
</dependency>
<dependency>
@@ -523,7 +523,7 @@
<aether.version>1.13.1</aether.version>
<wagon.version>1.0</wagon.version>
<maven.version>3.0.5</maven.version>
<mustache.version>0.8.14</mustache.version>
<mustache.version>0.8.15</mustache.version>
<netbeans.hint.deploy.server>Tomcat</netbeans.hint.deploy.server>
</properties>

View File

@@ -71,6 +71,7 @@ import sonia.scm.plugin.PluginManager;
import sonia.scm.repository.DefaultRepositoryManager;
import sonia.scm.repository.DefaultRepositoryProvider;
import sonia.scm.repository.HealthCheckContextListener;
import sonia.scm.repository.LastModifiedUpdateListener;
import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryDAO;
import sonia.scm.repository.RepositoryManager;
@@ -141,6 +142,7 @@ import com.sun.jersey.spi.container.servlet.ServletContainer;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
*
@@ -356,10 +358,12 @@ public class ScmServletModule extends JerseyServletModule
bind(TemplateEngine.class).annotatedWith(DefaultEngine.class).to(
MustacheTemplateEngine.class);
bind(TemplateEngineFactory.class);
// bind events
bind(LastModifiedUpdateListener.class);
// jersey
Map<String, String> params = new HashMap<String, String>();
/*
* params.put("com.sun.jersey.spi.container.ContainerRequestFilters",
* "com.sun.jersey.api.container.filter.LoggingFilter");
@@ -370,14 +374,14 @@ public class ScmServletModule extends JerseyServletModule
*/
params.put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE.toString());
params.put(ResourceConfig.FEATURE_REDIRECT, Boolean.TRUE.toString());
params.put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE.toString());
/*
* TODO remove UriExtensionsConfig and PackagesResourceConfig
* to stop jersey classpath scanning
*/
params.put(ServletContainer.RESOURCE_CONFIG_CLASS,
UriExtensionsConfig.class.getName());
UriExtensionsConfig.class.getName());
params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "unbound");
serve(PATTERN_RESTAPI).with(GuiceContainer.class, params);
}

View File

@@ -30,18 +30,30 @@
*/
package sonia.scm.api.rest;
//~--- JDK imports ------------------------------------------------------------
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author Sebastian Sdorra
*/
@XmlRootElement(name="result")
@XmlRootElement(name = "result")
public class RestActionUploadResult extends RestActionResult
{
/**
* Constructs ...
*
*/
public RestActionUploadResult()
{
this(true);
}
/**
* Constructs ...
*

View File

@@ -196,7 +196,7 @@ public abstract class AbstractManagerResource<T extends ModelObject,
}
catch (Exception ex)
{
logger.error("error during create", ex);
logger.error("error during delete", ex);
response = createErrorResonse(ex);
}
}
@@ -230,7 +230,7 @@ public abstract class AbstractManagerResource<T extends ModelObject,
}
catch (ScmSecurityException ex)
{
logger.warn("delete not allowd", ex);
logger.warn("update not allowd", ex);
response = Response.status(Response.Status.FORBIDDEN).build();
}
catch (Exception ex)

View File

@@ -72,12 +72,23 @@ public class BootstrapFilter implements Filter
@Override
public void destroy()
{
if (classLoader != null)
{
Thread.currentThread().setContextClassLoader(classLoader);
}
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
guiceFilter.destroy();
try
{
if (classLoader != null)
{
Thread.currentThread().setContextClassLoader(classLoader);
}
logger.debug("destroy guice filter");
guiceFilter.destroy();
}
finally
{
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
/**
@@ -93,15 +104,24 @@ public class BootstrapFilter implements Filter
*/
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException
FilterChain chain)
throws IOException, ServletException
{
if (classLoader != null)
{
Thread.currentThread().setContextClassLoader(classLoader);
}
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
guiceFilter.doFilter(request, response, chain);
try
{
if (classLoader != null)
{
Thread.currentThread().setContextClassLoader(classLoader);
}
guiceFilter.doFilter(request, response, chain);
}
finally
{
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
/**

View File

@@ -35,22 +35,27 @@ package sonia.scm.boot;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.SCMContext;
import sonia.scm.SCMContextProvider;
import sonia.scm.util.ClassLoaders;
import sonia.scm.util.IOUtil;
//~--- JDK imports ------------------------------------------------------------
import java.io.Closeable;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
@@ -89,8 +94,28 @@ public class BootstrapListener implements ServletContextListener
{
if (scmContextListener != null)
{
logger.info("destroy scm context listener");
scmContextListener.contextDestroyed(sce);
}
ServletContext servletContext = sce.getServletContext();
ClassLoader classLoader = BootstrapUtil.getClassLoader(servletContext);
if (classLoader != null)
{
if (classLoader instanceof Closeable)
{
logger.info("close plugin class loader");
IOUtil.close((Closeable) classLoader);
}
logger.debug("remove plugin class loader from servlet context");
BootstrapUtil.removeClassLoader(servletContext);
}
else
{
logger.debug("plugin class loader is not available");
}
}
/**
@@ -110,6 +135,44 @@ public class BootstrapListener implements ServletContextListener
context.getStage());
}
ClassLoader classLoader = createClassLoader(context);
if (classLoader != null)
{
if (logger.isInfoEnabled())
{
logger.info("try to use ScmBootstrapClassLoader");
}
scmContextListener = BootstrapUtil.loadClass(classLoader,
ServletContextListener.class, LISTENER);
BootstrapUtil.setClassLoader(sce.getServletContext(), classLoader);
}
if (scmContextListener == null)
{
if (logger.isWarnEnabled())
{
logger.warn("fallback to default classloader");
}
scmContextListener =
BootstrapUtil.loadClass(ServletContextListener.class, LISTENER);
}
initializeContext(classLoader, scmContextListener, sce);
}
/**
* Method description
*
*
* @param context
*
* @return
*/
private ClassLoader createClassLoader(SCMContextProvider context)
{
ClassLoader classLoader = null;
File pluginDirectory = new File(context.getBaseDirectory(),
PLUGIN_DIRECTORY);
@@ -144,31 +207,7 @@ public class BootstrapListener implements ServletContextListener
logger.debug("no plugin directory found");
}
if (classLoader != null)
{
if (logger.isInfoEnabled())
{
logger.info("try to use ScmBootstrapClassLoader");
}
scmContextListener = BootstrapUtil.loadClass(classLoader,
ServletContextListener.class, LISTENER);
Thread.currentThread().setContextClassLoader(classLoader);
BootstrapUtil.setClassLoader(sce.getServletContext(), classLoader);
}
if (scmContextListener == null)
{
if (logger.isWarnEnabled())
{
logger.warn("fallback to default classloader");
}
scmContextListener =
BootstrapUtil.loadClass(ServletContextListener.class, LISTENER);
}
scmContextListener.contextInitialized(sce);
return classLoader;
}
/**
@@ -188,7 +227,7 @@ public class BootstrapListener implements ServletContextListener
logger.debug("create classloader from plugin classpath");
}
List<URL> classpathURLs = new LinkedList<URL>();
List<URL> classpathURLs = Lists.newLinkedList();
for (String path : classpath)
{
@@ -224,32 +263,36 @@ public class BootstrapListener implements ServletContextListener
}
return BootstrapUtil.createClassLoader(classpathURLs,
getParentClassLoader());
ClassLoaders.getContextClassLoader(BootstrapListener.class));
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @return
* @param classLoader
* @param listener
* @param sce
*/
private ClassLoader getParentClassLoader()
private void initializeContext(ClassLoader classLoader,
ServletContextListener listener, ServletContextEvent sce)
{
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null)
try
{
if (logger.isWarnEnabled())
if (classLoader != null)
{
logger.warn("could not use context classloader, try to use default");
Thread.currentThread().setContextClassLoader(classLoader);
}
classLoader = BootstrapListener.class.getClassLoader();
logger.info("initialize scm context listener");
listener.contextInitialized(sce);
}
finally
{
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
return classLoader;
}
//~--- fields ---------------------------------------------------------------

View File

@@ -40,12 +40,12 @@ import com.google.common.base.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.net.ChildFirstURLClassLoader;
import sonia.scm.plugin.ChildFirstPluginClassLoader;
import sonia.scm.plugin.DefaultPluginClassLoader;
//~--- JDK imports ------------------------------------------------------------
import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;
@@ -107,7 +107,7 @@ public final class BootstrapUtil
{
logger.info("using {} as plugin classloading strategy",
STRATEGY_CHILDFIRST);
classLoader = new ChildFirstURLClassLoader(urls, parent);
classLoader = new ChildFirstPluginClassLoader(urls, parent);
}
else if (!STRATEGY_PARENTFIRST.equals(strategy))
{
@@ -119,7 +119,7 @@ public final class BootstrapUtil
{
logger.info("using {} as plugin classloading strategy",
STRATEGY_PARENTFIRST);
classLoader = new URLClassLoader(urls, parent);
classLoader = new DefaultPluginClassLoader(urls, parent);
}
return classLoader;
@@ -238,4 +238,17 @@ public final class BootstrapUtil
{
context.setAttribute(CLASSLOADER, classLoader);
}
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param context
*/
public static void removeClassLoader(ServletContext context)
{
context.removeAttribute(CLASSLOADER);
}
}

View File

@@ -0,0 +1,73 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.plugin;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.net.ChildFirstURLClassLoader;
//~--- JDK imports ------------------------------------------------------------
import java.net.URL;
/**
* Child first {@link ClassLoader} for SCM-Manager plugins.
*
* @author Sebastian Sdorra
*/
public class ChildFirstPluginClassLoader extends ChildFirstURLClassLoader
implements PluginClassLoader
{
/**
* Constructs ...
*
*
* @param urls
*/
public ChildFirstPluginClassLoader(URL[] urls)
{
super(urls);
}
/**
* Constructs ...
*
*
* @param urls
* @param parent
*/
public ChildFirstPluginClassLoader(URL[] urls, ClassLoader parent)
{
super(urls, parent);
}
}

View File

@@ -0,0 +1,71 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.plugin;
//~--- JDK imports ------------------------------------------------------------
import java.net.URL;
import java.net.URLClassLoader;
/**
* Default {@link ClassLoader} for SCM-Manager plugins. This {@link ClassLoader}
* uses the default parent first strategy.
*
* @author Sebastian Sdorra
*/
public class DefaultPluginClassLoader extends URLClassLoader
implements PluginClassLoader
{
/**
* Constructs ...
*
*
* @param urls
*/
public DefaultPluginClassLoader(URL[] urls)
{
super(urls);
}
/**
* Constructs ...
*
*
* @param urls
* @param parent
*/
public DefaultPluginClassLoader(URL[] urls, ClassLoader parent)
{
super(urls, parent);
}
}

View File

@@ -0,0 +1,40 @@
/**
* Copyright (c) 2010, Sebastian Sdorra All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of SCM-Manager;
* nor the names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* http://bitbucket.org/sdorra/scm-manager
*
*/
package sonia.scm.plugin;
/**
* The PluginClassLoader interface is mainly a marker to find the class loader
* in a memory dump. This should make it easier to find class loader leaks.
*
* @author Sebastian Sdorra
*/
public interface PluginClassLoader {}

View File

@@ -31,4 +31,4 @@
-->
<Context antiJARLocking="true" path="/scm"/>
<Context path="/scm"/>

View File

@@ -125,7 +125,11 @@ Sonia.repository.InfoPanel = Ext.extend(Ext.Panel, {
var index = uri.indexOf("://");
if ( index > 0 ){
index += 3;
uri = uri.substring(0, index) + state.user.name + "@" + uri.substring(index);
var username = state.user.name;
// escape backslash for active directory users
// see https://bitbucket.org/sdorra/scm-manager/issue/570/incorrect-git-checkout-url-generated-for
username = username.replace('\\', '\\\\');
uri = uri.substring(0, index) + username + "@" + uri.substring(index);
}
}
return uri;