use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.
the class ConnectorTestSuite method testTransferZeroBytesFile.
/**
* See https://issues.sonatype.org/browse/AETHER-8
*/
@Test
public void testTransferZeroBytesFile() throws IOException, NoRepositoryConnectorException {
File emptyFile = TestFileUtils.createTempFile("");
Artifact artifact = new StubArtifact("gid:aid:ext:ver");
ArtifactUpload upA = new ArtifactUpload(artifact, emptyFile);
File dir = TestFileUtils.createTempDir("con-test");
File downAFile = new File(dir, "downA.file");
downAFile.deleteOnExit();
ArtifactDownload downA = new ArtifactDownload(artifact, "", downAFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
Metadata metadata = new StubMetadata("gid", "aid", "ver", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
MetadataUpload upM = new MetadataUpload(metadata, emptyFile);
File downMFile = new File(dir, "downM.file");
downMFile.deleteOnExit();
MetadataDownload downM = new MetadataDownload(metadata, "", downMFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
RepositoryConnector connector = factory().newInstance(session, repository);
connector.put(Arrays.asList(upA), Arrays.asList(upM));
connector.get(Arrays.asList(downA), Arrays.asList(downM));
assertNull(String.valueOf(upA.getException()), upA.getException());
assertNull(String.valueOf(upM.getException()), upM.getException());
assertNull(String.valueOf(downA.getException()), downA.getException());
assertNull(String.valueOf(downM.getException()), downM.getException());
assertEquals(0, downAFile.length());
assertEquals(0, downMFile.length());
connector.close();
}
use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.
the class ConnectorTestUtils method createTransfers.
/**
* Creates transfer objects according to the given class. If the file parameter is {@code null}, a new temporary
* file will be created for downloads. Uploads will just use the parameter as it is.
*/
public static <T extends Transfer> List<T> createTransfers(Class<T> cls, int count, File file) {
ArrayList<T> ret = new ArrayList<T>();
Object item;
if (ArtifactTransfer.class.isAssignableFrom(cls)) {
item = new StubArtifact("testGroup", "testArtifact", "sources", "jar", "will be replaced");
} else {
item = new StubMetadata("testGroup", "testArtifact", "will be replaced", "jar", Metadata.Nature.RELEASE_OR_SNAPSHOT, file);
}
for (int i = 0; i < count; i++) {
String context = null;
String checksumPolicy = RepositoryPolicy.CHECKSUM_POLICY_IGNORE;
Object obj = null;
if (cls.isAssignableFrom(ArtifactUpload.class)) {
Artifact artifact = ((Artifact) item).setVersion((i + 1) + "-test");
obj = new ArtifactUpload(artifact, file);
} else if (cls.isAssignableFrom(ArtifactDownload.class)) {
try {
Artifact artifact = ((Artifact) item).setVersion((i + 1) + "-test");
obj = new ArtifactDownload(artifact, context, safeFile(file), checksumPolicy);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
} else if (cls.isAssignableFrom(MetadataUpload.class)) {
Metadata metadata = ((StubMetadata) item).setVersion((i + 1) + "-test");
obj = new MetadataUpload(metadata, file);
} else if (cls.isAssignableFrom(MetadataDownload.class)) {
try {
Metadata metadata = ((StubMetadata) item).setVersion((i + 1) + "-test");
obj = new MetadataDownload(metadata, context, safeFile(file), checksumPolicy);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
ret.add(cls.cast(obj));
}
return ret;
}
use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.
the class RecordingRepositoryConnector method get.
public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
try {
if (artifactDownloads != null) {
for (ArtifactDownload artifactDownload : artifactDownloads) {
artifactDownload.setState(State.ACTIVE);
Artifact artifact = artifactDownload.getArtifact();
this.actualGet.add(artifact);
TestFileUtils.write(artifact.toString(), artifactDownload.getFile());
artifactDownload.setState(State.DONE);
}
}
if (metadataDownloads != null) {
for (MetadataDownload metadataDownload : metadataDownloads) {
metadataDownload.setState(State.ACTIVE);
Metadata metadata = metadataDownload.getMetadata();
this.actualGetMD.add(metadata);
TestFileUtils.write(metadata.toString(), metadataDownload.getFile());
metadataDownload.setState(State.DONE);
}
}
} catch (IOException e) {
throw new IllegalStateException("Cannot create temporary file", e);
}
}
use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.
the class TestLocalRepositoryManager method find.
public LocalMetadataResult find(RepositorySystemSession session, LocalMetadataRequest request) {
Metadata metadata = request.getMetadata();
LocalMetadataResult result = new LocalMetadataResult(request);
File file = new File(localRepository.getBasedir(), getPathForLocalMetadata(metadata));
result.setFile(file.isFile() ? file : null);
return result;
}
use of org.sonatype.aether.metadata.Metadata in project sonatype-aether by sonatype.
the class DefaultUpdateCheckManager method checkMetadata.
public void checkMetadata(RepositorySystemSession session, UpdateCheck<Metadata, MetadataTransferException> check) {
if (check.getLocalLastUpdated() != 0 && !isUpdatedRequired(session, check.getLocalLastUpdated(), check.getPolicy())) {
if (logger.isDebugEnabled()) {
logger.debug("Skipped remote update check for " + check.getItem() + ", locally installed metadata up-to-date.");
}
check.setRequired(false);
return;
}
Metadata metadata = check.getItem();
RemoteRepository repository = check.getRepository();
File metadataFile = check.getFile();
if (metadataFile == null) {
throw new IllegalArgumentException(String.format("The metadata '%s' has no file attached", metadata));
}
boolean fileExists = check.isFileValid() && metadataFile.exists();
File touchFile = getTouchFile(metadata, metadataFile);
Properties props = read(touchFile);
String updateKey = getUpdateKey(metadataFile, repository);
String dataKey = getDataKey(metadata, metadataFile, check.getAuthoritativeRepository());
String error = getError(props, dataKey);
long lastUpdated;
if (error == null) {
if (fileExists) {
// last update was successful
lastUpdated = getLastUpdated(props, dataKey);
} else {
// this is the first attempt ever
lastUpdated = 0;
}
} else if (error.length() <= 0) {
// metadata did not exist
lastUpdated = getLastUpdated(props, dataKey);
} else {
// metadata could not be transferred
String transferKey = getTransferKey(metadata, metadataFile, repository);
lastUpdated = getLastUpdated(props, transferKey);
}
if (isAlreadyUpdated(session.getData(), updateKey)) {
if (logger.isDebugEnabled()) {
logger.debug("Skipped remote update check for " + check.getItem() + ", already updated during this session.");
}
check.setRequired(false);
if (error != null) {
check.setException(newException(error, metadata, repository));
}
} else if (lastUpdated == 0) {
check.setRequired(true);
} else if (isUpdatedRequired(session, lastUpdated, check.getPolicy())) {
check.setRequired(true);
} else if (fileExists) {
if (logger.isDebugEnabled()) {
logger.debug("Skipped remote update check for " + check.getItem() + ", locally cached metadata up-to-date.");
}
check.setRequired(false);
} else {
if (error == null || error.length() <= 0) {
check.setRequired(false);
check.setException(newException(error, metadata, repository));
} else {
if (session.isTransferErrorCachingEnabled()) {
check.setRequired(false);
check.setException(newException(error, metadata, repository));
} else {
check.setRequired(true);
}
}
}
}
Aggregations