aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2019-06-30 22:47:24 +0200
committerMartin Stockhammer <martin_s@apache.org>2019-06-30 22:47:24 +0200
commit9ca52f4e279159bfd5623585d2a84c2cde0e3421 (patch)
tree2c697e37539365913fd9a2b949d7f04e9bf8f823 /archiva-modules/archiva-base
parent23099bcb581738f3c9cb13745ae2837eafd77ec6 (diff)
downloadarchiva-9ca52f4e279159bfd5623585d2a84c2cde0e3421.tar.gz
archiva-9ca52f4e279159bfd5623585d2a84c2cde0e3421.zip
Fixing tests after refactoring
Diffstat (limited to 'archiva-modules/archiva-base')
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java16
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/RepositoryGroupConfiguration.java3
-rw-r--r--archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java3
-rwxr-xr-xarchiva-modules/archiva-base/archiva-configuration/src/test/resources/spring-context.xml8
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/RepositoryProviderMock.java5
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java4
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/ArchivaIndexManager.java3
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java4
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/StorageAsset.java12
-rw-r--r--archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java5
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepository.java7
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepositoryGroup.java9
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java10
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/FilesystemAsset.java54
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/FilesystemStorage.java6
-rw-r--r--archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanner.java7
-rw-r--r--archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScannerInstance.java3
17 files changed, 128 insertions, 31 deletions
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java
index 13e8a2898..8b633c7ca 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java
@@ -606,7 +606,7 @@ public class DefaultArchivaConfiguration
if (!writeFile("user configuration", userConfigFilename, contents)) {
fileLocation = altConfigFilename;
- if (!writeFile("alternative configuration", altConfigFilename, contents)) {
+ if (!writeFile("alternative configuration", altConfigFilename, contents, true)) {
throw new RegistryException(
"Unable to create configuration file in either user [" + userConfigFilename + "] or alternative ["
+ altConfigFilename
@@ -632,6 +632,10 @@ public class DefaultArchivaConfiguration
return section == null ? new CommonsConfigurationRegistry(new BaseConfiguration()) : section;
}
+ private boolean writeFile(String filetype, String path, String contents) {
+ return writeFile( filetype, path, contents, false );
+ }
+
/**
* Attempts to write the contents to a file, if an IOException occurs, return false.
* <p/>
@@ -642,14 +646,18 @@ public class DefaultArchivaConfiguration
* @param contents the contents to write.
* @return true if write successful.
*/
- private boolean writeFile(String filetype, String path, String contents) {
+ private boolean writeFile(String filetype, String path, String contents, boolean createDirs) {
Path file = Paths.get(path);
try {
// Check parent directory (if it is declared)
- if (file.getParent() != null) {
+ final Path parent = file.getParent();
+ if (parent != null) {
// Check that directory exists
- if (!Files.isDirectory(file.getParent())) {
+ if (!Files.exists( parent ) && createDirs) {
+ Files.createDirectories( parent );
+ }
+ if (!Files.isDirectory(parent)) {
// Directory to file must exist for file to be created
return false;
}
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/RepositoryGroupConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/RepositoryGroupConfiguration.java
index db3498be3..cf518951c 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/RepositoryGroupConfiguration.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/RepositoryGroupConfiguration.java
@@ -69,8 +69,7 @@ public class RepositoryGroupConfiguration
/**
*
* When to run the index merging for this group.
- * No default value.
- *
+ *
*/
private String cronExpression = "";
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java
index cd1635d6b..288986aaa 100644
--- a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java
+++ b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ArchivaConfigurationTest.java
@@ -34,6 +34,7 @@ import org.springframework.test.context.ContextConfiguration;
import javax.inject.Inject;
import java.nio.charset.Charset;
+import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -508,7 +509,7 @@ public class ArchivaConfigurationTest
throws Exception
{
String propFile = System.getProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY );
- System.setProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY, "${basedir}/target/*intentionally:invalid*/.m2/archiva-user.xml" );
+ System.setProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY, "/../../..//*intentionally:invalid*/.m2/archiva-user.xml" );
ArchivaConfiguration archivaConfiguration =
lookup( ArchivaConfiguration.class, "test-not-allowed-to-write-to-both" );
Configuration config = archivaConfiguration.getConfiguration();
diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/resources/spring-context.xml b/archiva-modules/archiva-base/archiva-configuration/src/test/resources/spring-context.xml
index fd941ccda..f0bd4e10d 100755
--- a/archiva-modules/archiva-base/archiva-configuration/src/test/resources/spring-context.xml
+++ b/archiva-modules/archiva-base/archiva-configuration/src/test/resources/spring-context.xml
@@ -283,8 +283,8 @@
<bean name="archivaConfiguration#test-not-allowed-to-write-to-both" class="org.apache.archiva.configuration.DefaultArchivaConfiguration">
<property name="registry" ref="registry#test-not-allowed-to-write-to-both"/>
- <property name="userConfigFilename" value="${basedir}/target/*intentionally:invalid*/.m2/archiva-user.xml"/>
- <property name="altConfigFilename" value="${basedir}/target/*intentionally:invalid*/conf/archiva.xml"/>
+ <property name="userConfigFilename" value="/../../..//target/*intentionally:invalid*/.m2/archiva-user.xml"/>
+ <property name="altConfigFilename" value="/../../..//target/*intentionally:invalid*/conf/archiva.xml"/>
</bean>
<bean name="registry#test-not-allowed-to-write-to-both" class="org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry">
@@ -292,9 +292,9 @@
<value>
<![CDATA[
<configuration>
- <xml fileName="${basedir}/target/*intentionally:invalid*/.m2/archiva-user.xml" config-optional="true"
+ <xml fileName="/../../..//*intentionally:invalid*/.m2/archiva-user.xml" config-optional="true"
config-name="org.apache.archiva.user" config-at="org.apache.archiva"/>
- <xml fileName="${basedir}/target/*intentionally:invalid*/conf/archiva.xml" config-optional="true"
+ <xml fileName="/../../..//*intentionally:invalid*/conf/archiva.xml" config-optional="true"
config-name="org.apache.archiva.user" config-at="org.apache.archiva"/>
</configuration>
]]>
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/RepositoryProviderMock.java b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/RepositoryProviderMock.java
index ea7b0f653..7f72c4205 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/RepositoryProviderMock.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/RepositoryProviderMock.java
@@ -246,6 +246,11 @@ public class RepositoryProviderMock implements RepositoryProvider
public RepositoryGroup createRepositoryGroup(RepositoryGroupConfiguration configuration) throws RepositoryException {
return null;
}
+ @Override
+ public EditableRepositoryGroup createRepositoryGroup(String id, String name) {
+ return null;
+ }
+
@Override
public void updateRepositoryGroupInstance(EditableRepositoryGroup repositoryGroup, RepositoryGroupConfiguration configuration) throws RepositoryException {
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java
index 6c25e3a67..74bafcd7d 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/beans/RepositoryGroup.java
@@ -23,6 +23,8 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
+import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_INDEX_PATH;
+
/**
* @author Olivier Lamy
* @since 1.4-M1
@@ -44,7 +46,7 @@ public class RepositoryGroup
/**
* The path of the merged index.
*/
- private String mergedIndexPath = ".indexer";
+ private String mergedIndexPath = DEFAULT_INDEX_PATH;
/**
* The TTL (time to live) of the repo group's merged index.
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/ArchivaIndexManager.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/ArchivaIndexManager.java
index cbf2472f7..5eb57705f 100644
--- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/ArchivaIndexManager.java
+++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/ArchivaIndexManager.java
@@ -30,6 +30,9 @@ import java.util.List;
public interface ArchivaIndexManager {
+ String DEFAULT_INDEX_PATH=".indexer";
+ String DEFAULT_PACKED_INDEX_PATH=".index";
+
/**
* Compresses the index to a more dense packed format.
* @param context
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java
index 0b3803f48..787e02d5b 100644
--- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java
+++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java
@@ -21,6 +21,8 @@ package org.apache.archiva.indexer.merger;
import java.nio.file.Path;
import java.util.Collection;
+import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_INDEX_PATH;
+
/**
* @author Olivier Lamy
*/
@@ -41,7 +43,7 @@ public class IndexMergerRequest
*/
private String groupId;
- private String mergedIndexPath = ".indexer";
+ private String mergedIndexPath = DEFAULT_INDEX_PATH;
private int mergedIndexTtl;
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/StorageAsset.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/StorageAsset.java
index 008f096a3..16e70859d 100644
--- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/StorageAsset.java
+++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/content/StorageAsset.java
@@ -128,4 +128,16 @@ public interface StorageAsset
* @throws UnsupportedOperationException
*/
Path getFilePath() throws UnsupportedOperationException;
+
+ /**
+ * Returns true, if there is a parent to this asset.
+ * @return
+ */
+ boolean hasParent();
+
+ /**
+ * Returns the parent of this asset.
+ * @return The asset, or <code>null</code>, if it does not exist.
+ */
+ StorageAsset getParent();
}
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java
index d22f1dfe0..636e2cb40 100644
--- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java
+++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java
@@ -29,6 +29,9 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
+import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_INDEX_PATH;
+import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_PACKED_INDEX_PATH;
+
/**
*
* This feature provides some information about index creation.
@@ -36,8 +39,6 @@ import java.nio.file.Path;
*/
public class IndexCreationFeature extends AbstractFeature implements RepositoryFeature<IndexCreationFeature>{
- public static final String DEFAULT_INDEX_PATH = ".indexer";
- public static final String DEFAULT_PACKED_INDEX_PATH = ".index";
private boolean skipPackedIndexCreation = false;
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepository.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepository.java
index 52727080c..1627ddfaa 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepository.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepository.java
@@ -261,8 +261,11 @@ public abstract class AbstractRepository implements EditableRepository, Reposito
@Override
public void setSchedulingDefinition(String cronExpression) {
- CronParser parser = new CronParser(CRON_DEFINITION);
- parser.parse(cronExpression).validate();
+ if (StringUtils.isNotEmpty( cronExpression ))
+ {
+ CronParser parser = new CronParser( CRON_DEFINITION );
+ parser.parse( cronExpression ).validate( );
+ }
this.schedulingDefinition = cronExpression;
}
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepositoryGroup.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepositoryGroup.java
index 1fb61f540..48d2d2b0c 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepositoryGroup.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/AbstractRepositoryGroup.java
@@ -83,7 +83,8 @@ public class AbstractRepositoryGroup extends AbstractRepository implements Edita
try {
repositories.clear();
for(ManagedRepository repo : newRepositories) {
- repositories.put(repo.getId(), repo);
+ if (repo!=null)
+ repositories.put(repo.getId(), repo);
}
} finally {
rwl.writeLock().unlock();
@@ -94,7 +95,8 @@ public class AbstractRepositoryGroup extends AbstractRepository implements Edita
public void addRepository(ManagedRepository repository) {
rwl.writeLock().lock();
try {
- repositories.put(repository.getId(), repository);
+ if (repository!=null)
+ repositories.put(repository.getId(), repository);
} finally {
rwl.writeLock().unlock();
}
@@ -104,7 +106,8 @@ public class AbstractRepositoryGroup extends AbstractRepository implements Edita
public void addRepository(int index, ManagedRepository repository) {
rwl.writeLock().lock();
try {
- repositories.put(index, repository.getId(), repository);
+ if (repository!=null)
+ repositories.put(index, repository.getId(), repository);
} finally {
rwl.writeLock().unlock();
}
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java
index 79c28bbe1..2b0ac684a 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/RepositoryRegistry.java
@@ -42,13 +42,17 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_INDEX_PATH;
+
/**
* Registry for repositories. This is the central entry point for repositories. It provides methods for
* retrieving, adding and removing repositories.
@@ -177,6 +181,10 @@ public class RepositoryRegistry implements ConfigurationListener, RepositoryEven
Map<RepositoryType, RepositoryProvider> providerMap = createProviderMap( );
for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
{
+ if (managedRepos.containsKey(repoConfig.getId())) {
+ log.warn( "Duplicate repository definitions for {} in config found.", repoConfig.getId( ) );
+ continue;
+ }
RepositoryType repositoryType = RepositoryType.valueOf( repoConfig.getType( ) );
if ( providerMap.containsKey( repositoryType ) )
{
@@ -817,7 +825,7 @@ public class RepositoryRegistry implements ConfigurationListener, RepositoryEven
private void setRepositoryGroupDefaults(RepositoryGroupConfiguration repositoryGroupConfiguration) {
if (StringUtils.isEmpty(repositoryGroupConfiguration.getMergedIndexPath())) {
- repositoryGroupConfiguration.setMergedIndexPath(".indexer");
+ repositoryGroupConfiguration.setMergedIndexPath(DEFAULT_INDEX_PATH);
}
if (repositoryGroupConfiguration.getMergedIndexTtl()<=0) {
repositoryGroupConfiguration.setMergedIndexTtl(300);
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/FilesystemAsset.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/FilesystemAsset.java
index 6baed7869..41b45dfdc 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/FilesystemAsset.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/FilesystemAsset.java
@@ -19,6 +19,7 @@ package org.apache.archiva.repository.content;
* under the License.
*/
+import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,6 +49,7 @@ public class FilesystemAsset implements StorageAsset {
private final static Logger log = LoggerFactory.getLogger(FilesystemAsset.class);
+ private final Path basePath;
private final Path assetPath;
private final String relativePath;
@@ -86,6 +88,15 @@ public class FilesystemAsset implements StorageAsset {
boolean directoryHint = false;
+
+ FilesystemAsset(String path, Path assetPath, Path basePath) {
+ this.assetPath = assetPath;
+ this.relativePath = path;
+ this.setPermissionsForNew=false;
+ this.basePath = basePath;
+ init();
+ }
+
/**
* Creates an asset for the given path. The given paths are not checked.
* The base path should be an absolute path.
@@ -97,6 +108,7 @@ public class FilesystemAsset implements StorageAsset {
this.assetPath = assetPath;
this.relativePath = path;
this.setPermissionsForNew = false;
+ this.basePath = null;
init();
}
@@ -109,11 +121,12 @@ public class FilesystemAsset implements StorageAsset {
* @param directory This is only relevant, if the represented file or directory does not exist yet and
* is a hint.
*/
- public FilesystemAsset(String path, Path assetPath, boolean directory) {
+ public FilesystemAsset(String path, Path assetPath, Path basePath, boolean directory) {
this.assetPath = assetPath;
this.relativePath = path;
this.directoryHint = directory;
this.setPermissionsForNew = false;
+ this.basePath = basePath;
init();
}
@@ -126,11 +139,12 @@ public class FilesystemAsset implements StorageAsset {
* @param directory This is only relevant, if the represented file or directory does not exist yet and
* is a hint.
*/
- public FilesystemAsset(String path, Path assetPath, boolean directory, boolean setPermissionsForNew) {
+ public FilesystemAsset(String path, Path assetPath, Path basePath, boolean directory, boolean setPermissionsForNew) {
this.assetPath = assetPath;
this.relativePath = path;
this.directoryHint = directory;
this.setPermissionsForNew = setPermissionsForNew;
+ this.basePath = basePath;
init();
}
@@ -263,6 +277,9 @@ public class FilesystemAsset implements StorageAsset {
} else {
options = new OpenOption[]{StandardOpenOption.APPEND};
}
+ if (!Files.exists( assetPath )) {
+ create();
+ }
return Files.newOutputStream(assetPath, options);
}
@@ -344,6 +361,33 @@ public class FilesystemAsset implements StorageAsset {
return assetPath;
}
+ @Override
+ public boolean hasParent( )
+ {
+ if (basePath!=null && assetPath.equals(basePath)) {
+ return false;
+ }
+ return assetPath.getParent()!=null;
+ }
+
+ @Override
+ public StorageAsset getParent( )
+ {
+ Path parentPath;
+ if (basePath!=null && assetPath.equals( basePath )) {
+ parentPath=null;
+ } else
+ {
+ parentPath = assetPath.getParent( );
+ }
+ String relativeParent = StringUtils.substringBeforeLast( relativePath,"/");
+ if (parentPath!=null) {
+ return new FilesystemAsset( relativeParent, parentPath, basePath, true, setPermissionsForNew );
+ } else {
+ return null;
+ }
+ }
+
public void setDefaultFileAcls(List<AclEntry> acl) {
defaultFileAcls = acl;
@@ -383,6 +427,9 @@ public class FilesystemAsset implements StorageAsset {
if (directoryHint) {
Files.createDirectories(assetPath);
} else {
+ if (!Files.exists( assetPath.getParent() )) {
+ Files.createDirectories( assetPath.getParent( ) );
+ }
Files.createFile(assetPath);
}
if (setPermissionsForNew) {
@@ -393,8 +440,7 @@ public class FilesystemAsset implements StorageAsset {
@Override
public String toString() {
- return relativePath;
+ return relativePath+":"+assetPath;
}
-
}
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/FilesystemStorage.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/FilesystemStorage.java
index f24b31137..25e0bc506 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/FilesystemStorage.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/FilesystemStorage.java
@@ -142,7 +142,7 @@ public class FilesystemStorage implements RepositoryStorage {
public StorageAsset addAsset( String path, boolean container )
{
try {
- return new FilesystemAsset( path, getAssetPath(path), container);
+ return new FilesystemAsset( path, getAssetPath(path), basePath, container);
} catch (IOException e) {
throw new IllegalArgumentException("Path navigates outside of base directory "+path);
}
@@ -158,7 +158,7 @@ public class FilesystemStorage implements RepositoryStorage {
public StorageAsset moveAsset( StorageAsset origin, String destination ) throws IOException
{
boolean container = origin.isContainer();
- FilesystemAsset newAsset = new FilesystemAsset( destination, getAssetPath(destination), container );
+ FilesystemAsset newAsset = new FilesystemAsset( destination, getAssetPath(destination), basePath, container );
Files.move(origin.getFilePath(), newAsset.getFilePath());
return newAsset;
}
@@ -167,7 +167,7 @@ public class FilesystemStorage implements RepositoryStorage {
public StorageAsset copyAsset( StorageAsset origin, String destination ) throws IOException
{
boolean container = origin.isContainer();
- FilesystemAsset newAsset = new FilesystemAsset( destination, getAssetPath(destination), container );
+ FilesystemAsset newAsset = new FilesystemAsset( destination, getAssetPath(destination), basePath, container );
if (Files.exists(newAsset.getFilePath())) {
throw new IOException("Destination file exists already "+ newAsset.getFilePath());
}
diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanner.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanner.java
index 8c5cb8946..bf85f53b4 100644
--- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanner.java
+++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScanner.java
@@ -26,6 +26,9 @@ import org.apache.archiva.repository.ManagedRepository;
import java.util.List;
import java.util.Set;
+import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_INDEX_PATH;
+import static org.apache.archiva.indexer.ArchivaIndexManager.DEFAULT_PACKED_INDEX_PATH;
+
/**
* RepositoryScanner
*
@@ -51,9 +54,9 @@ public interface RepositoryScanner
* </p>
*/
static final String[] IGNORABLE_CONTENT =
- { "bin/**", "reports/**", ".index", ".reports/**", ".maven/**", "**/.svn/**", "**/*snapshot-version",
+ { "bin/**", "reports/**", DEFAULT_PACKED_INDEX_PATH, ".reports/**", ".maven/**", "**/.svn/**", "**/*snapshot-version",
"*/website/**", "*/licences/**", "**/.htaccess", "**/*.html", "**/*.txt", "**/README*", "**/CHANGELOG*",
- "**/KEYS*", ".indexer" };
+ "**/KEYS*", DEFAULT_INDEX_PATH };
/**
* Scan the repository for content changes.
diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScannerInstance.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScannerInstance.java
index 302c623df..425a4c53d 100644
--- a/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScannerInstance.java
+++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryScannerInstance.java
@@ -223,7 +223,8 @@ public class RepositoryScannerInstance
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
- if (excludeMatcher.stream().noneMatch(m -> m.matches(file)) && includeMatcher.stream().allMatch(m -> m.matches(file))) {
+ final Path relativeFile = basePath.relativize( file );
+ if (excludeMatcher.stream().noneMatch(m -> m.matches(relativeFile)) && includeMatcher.stream().allMatch(m -> m.matches(relativeFile))) {
log.debug( "Walk Step: {}, {}", file );
stats.increaseFileCount();