use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project gradle by gradle.
the class AbstractMavenResolver method publish.
public void publish(IvyModulePublishMetadata moduleVersion) {
for (IvyModuleArtifactPublishMetadata artifactMetadata : moduleVersion.getArtifacts()) {
IvyArtifactName artifact = artifactMetadata.getArtifactName();
ModuleRevisionId moduleRevisionId = IvyUtil.createModuleRevisionId(artifactMetadata.getId().getComponentIdentifier());
Map<String, String> attributes = Collections.singletonMap("classifier", artifact.getClassifier());
Artifact ivyArtifact = new DefaultArtifact(moduleRevisionId, null, artifact.getName(), artifact.getType(), artifact.getExtension(), attributes);
collectArtifact(ivyArtifact, artifactMetadata.getFile());
}
publish();
}
use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project ant-ivy by apache.
the class AbstractWorkspaceResolver method checkCandidate.
protected ResolvedModuleRevision checkCandidate(DependencyDescriptor dd, ModuleDescriptor md, String workspaceModuleName) {
if (workspaceModuleName == null) {
workspaceModuleName = dd.getDependencyId().toString();
}
ModuleRevisionId dependencyMrid = dd.getDependencyRevisionId();
String org = dependencyMrid.getModuleId().getOrganisation();
String module = dependencyMrid.getModuleId().getName();
VersionMatcher versionMatcher = getSettings().getVersionMatcher();
ModuleRevisionId candidateMrid = md.getModuleRevisionId();
switch(org) {
case BundleInfo.BUNDLE_TYPE:
// looking for an OSGi bundle via its symbolic name
String sn = md.getExtraInfoContentByTagName("Bundle-SymbolicName");
if (sn == null || !module.equals(sn)) {
// not found, skip to next
return null;
}
break;
case BundleInfo.PACKAGE_TYPE:
// looking for an OSGi bundle via its exported package
String exportedPackages = md.getExtraInfoContentByTagName("Export-Package");
if (exportedPackages == null) {
// not found, skip to next
return null;
}
boolean found = false;
String version = null;
ManifestHeaderValue exportElements;
try {
exportElements = new ManifestHeaderValue(exportedPackages);
} catch (ParseException e) {
// wrong OSGi header: skip it
return null;
}
for (ManifestHeaderElement exportElement : exportElements.getElements()) {
if (exportElement.getValues().contains(module)) {
found = true;
version = exportElement.getAttributes().get("version");
break;
}
}
if (!found) {
// not found, skip to next
return null;
}
if (version == null) {
// no version means anything can match. Let's trick the version matcher by
// setting the exact expected version
version = dependencyMrid.getRevision();
}
md.setResolvedModuleRevisionId(ModuleRevisionId.newInstance(org, module, version));
break;
default:
if (!candidateMrid.getModuleId().equals(dependencyMrid.getModuleId())) {
// it doesn't match org#module, skip to next
return null;
}
break;
}
Message.verbose("Workspace resolver found potential matching workspace module " + workspaceModuleName + " with module " + candidateMrid + " for module " + dependencyMrid);
if (!ignoreBranch) {
ModuleId mid = dependencyMrid.getModuleId();
String defaultBranch = getSettings().getDefaultBranch(mid);
String dependencyBranch = dependencyMrid.getBranch();
String candidateBranch = candidateMrid.getBranch();
if (dependencyBranch == null) {
dependencyBranch = defaultBranch;
}
if (candidateBranch == null) {
candidateBranch = defaultBranch;
}
if (dependencyBranch != candidateBranch) {
// Both cannot be null
if (dependencyBranch == null || candidateBranch == null) {
Message.verbose("\t\trejected since branches doesn't match (one is set, the other isn't)");
return null;
}
if (!dependencyBranch.equals(candidateBranch)) {
Message.verbose("\t\trejected since branches doesn't match");
return null;
}
}
}
// Found one; check if it is for the module we need
if (!ignoreVersion && !md.getModuleRevisionId().getRevision().equals(Ivy.getWorkingRevision()) && !versionMatcher.accept(dd.getDependencyRevisionId(), md)) {
Message.verbose("\t\treject as version didn't match");
return null;
}
if (ignoreVersion) {
Message.verbose("\t\tmatched (version are ignored)");
} else {
Message.verbose("\t\tversion matched");
}
WorkspaceModuleDescriptor workspaceMd = createWorkspaceMd(md);
Artifact mdaf = md.getMetadataArtifact();
if (mdaf == null) {
mdaf = new DefaultArtifact(md.getModuleRevisionId(), md.getPublicationDate(), workspaceModuleName, "ivy", "");
}
MetadataArtifactDownloadReport madr = new MetadataArtifactDownloadReport(mdaf);
madr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
madr.setSearched(true);
return new ResolvedModuleRevision(this, this, workspaceMd, madr);
}
use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project ant-ivy by apache.
the class DefaultRepositoryCacheManager method getSavedArtifactOrigin.
public ArtifactOrigin getSavedArtifactOrigin(Artifact artifact) {
ModuleRevisionId mrid = artifact.getModuleRevisionId();
if (!lockMetadataArtifact(mrid)) {
Message.error("impossible to acquire lock for " + mrid);
return ArtifactOrigin.unknown(artifact);
}
try {
PropertiesFile cdf = getCachedDataFile(artifact.getModuleRevisionId());
String location = cdf.getProperty(getLocationKey(artifact));
String local = cdf.getProperty(getIsLocalKey(artifact));
String lastChecked = cdf.getProperty(getLastCheckedKey(artifact));
String exists = cdf.getProperty(getExistsKey(artifact));
String original = cdf.getProperty(getOriginalKey(artifact));
boolean isLocal = Boolean.valueOf(local);
if (location == null) {
// origin has not been specified, return null
return ArtifactOrigin.unknown(artifact);
}
if (original != null) {
// original artifact key artifact:[name]#[type]#[ext]#[hashcode]
java.util.regex.Matcher m = ARTIFACT_KEY_PATTERN.matcher(original);
if (m.matches()) {
String origName = m.group(1);
String origType = m.group(2);
String origExt = m.group(3);
ArtifactRevisionId originArtifactId = ArtifactRevisionId.newInstance(artifact.getModuleRevisionId(), origName, origType, origExt);
// second check: verify the hashcode of the cached artifact
if (m.group(4).equals("" + originArtifactId.hashCode())) {
try {
artifact = new DefaultArtifact(originArtifactId, artifact.getPublicationDate(), new URL(location), true);
} catch (MalformedURLException e) {
Message.debug(e);
}
}
}
} else {
// origin artifact for it
if (!location.endsWith("." + artifact.getExt())) {
// try to find other cached artifact info with same location. This must be the
// origin. We must parse the key as we do not know for sure what the original
// artifact is named.
String ownLocationKey = getLocationKey(artifact);
for (Map.Entry<Object, Object> entry : cdf.entrySet()) {
if (entry.getValue().equals(location) && !ownLocationKey.equals(entry.getKey())) {
// found a match, key is
// artifact:[name]#[type]#[ext]#[hashcode].location
java.util.regex.Matcher m = ARTIFACT_KEY_PATTERN.matcher((String) entry.getKey());
if (m.matches()) {
String origName = m.group(1);
String origType = m.group(2);
String origExt = m.group(3);
// first check: the type should end in .original
if (!origType.endsWith(".original")) {
continue;
}
ArtifactRevisionId originArtifactId = ArtifactRevisionId.newInstance(artifact.getModuleRevisionId(), origName, origType, origExt);
// second check: verify the hashcode of the cached artifact
if (m.group(4).equals("" + originArtifactId.hashCode())) {
try {
artifact = new DefaultArtifact(originArtifactId, artifact.getPublicationDate(), new URL(location), true);
} catch (MalformedURLException e) {
Message.debug(e);
}
}
break;
}
}
}
}
}
ArtifactOrigin origin = new ArtifactOrigin(artifact, isLocal, location);
if (lastChecked != null) {
origin.setLastChecked(Long.valueOf(lastChecked));
}
if (exists != null) {
origin.setExist(Boolean.valueOf(exists));
}
return origin;
} finally {
unlockMetadataArtifact(mrid);
}
}
use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project ant-ivy by apache.
the class DefaultRepositoryCacheManager method downloadRepositoryResource.
public ArtifactDownloadReport downloadRepositoryResource(final Resource resource, String name, String type, String extension, CacheResourceOptions options, Repository repository) {
String hash = computeResourceNameHash(resource);
ModuleRevisionId mrid = ModuleRevisionId.newInstance("_repository_metadata_", hash, Ivy.getWorkingRevision());
Artifact artifact = new DefaultArtifact(mrid, null, name, type, extension);
final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifact);
boolean useOrigin = isUseOrigin();
try {
DownloadListener listener = options.getListener();
if (listener != null) {
listener.needArtifact(this, artifact);
}
ArtifactOrigin savedOrigin = getSavedArtifactOrigin(artifact);
File archiveFile = getArchiveFileInCache(artifact, savedOrigin, useOrigin);
ArtifactOrigin origin = new ArtifactOrigin(artifact, resource.isLocal(), resource.getName());
if (!options.isForce() && // if the local file has been checked to be up to date enough recently, don't download
checkCacheUptodate(archiveFile, resource, savedOrigin, origin, options.getTtl())) {
if (archiveFile.exists()) {
saveArtifactOrigin(artifact, origin);
adr.setDownloadStatus(DownloadStatus.NO);
adr.setSize(archiveFile.length());
adr.setArtifactOrigin(savedOrigin);
adr.setLocalFile(archiveFile);
} else {
// we trust the cache to says that the resource doesn't exist
adr.setDownloadStatus(DownloadStatus.FAILED);
adr.setDownloadDetails("Remote resource is known to not exist");
}
} else {
long start = System.currentTimeMillis();
origin.setLastChecked(start);
try {
ResolvedResource artifactRef = new ResolvedResource(resource, Ivy.getWorkingRevision());
if (useOrigin && resource.isLocal()) {
saveArtifactOrigin(artifact, origin);
archiveFile = getArchiveFileInCache(artifact, origin);
adr.setDownloadStatus(DownloadStatus.NO);
adr.setSize(archiveFile.length());
adr.setArtifactOrigin(origin);
adr.setLocalFile(archiveFile);
} else {
if (listener != null) {
listener.startArtifactDownload(this, artifactRef, artifact, origin);
}
// actual download
if (archiveFile.exists()) {
archiveFile.delete();
}
File part = new File(archiveFile.getAbsolutePath() + ".part");
repository.get(resource.getName(), part);
if (!part.renameTo(archiveFile)) {
throw new IOException("impossible to move part file to definitive one: " + part + " -> " + archiveFile);
}
adr.setSize(archiveFile.length());
saveArtifactOrigin(artifact, origin);
adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
adr.setDownloadStatus(DownloadStatus.SUCCESSFUL);
adr.setArtifactOrigin(origin);
adr.setLocalFile(archiveFile);
}
} catch (Exception ex) {
Message.debug(ex);
origin.setExist(false);
saveArtifactOrigin(artifact, origin);
adr.setDownloadStatus(DownloadStatus.FAILED);
adr.setDownloadDetails(ex.getMessage());
adr.setDownloadTimeMillis(System.currentTimeMillis() - start);
}
}
if (listener != null) {
listener.endArtifactDownload(this, artifact, adr, archiveFile);
}
return adr;
} finally {
unlockMetadataArtifact(mrid);
}
}
use of org.apache.ivy.core.module.descriptor.DefaultArtifact in project ant-ivy by apache.
the class FileSystemResolverTest method testPublishTransactionWithDottedOrganisation.
@Test
public void testPublishTransactionWithDottedOrganisation() throws Exception {
FileSystemResolver resolver = new FileSystemResolver();
resolver.setName("test");
resolver.setM2compatible(true);
resolver.setSettings(settings);
resolver.addIvyPattern(settings.getBaseDir() + "/test/repositories/m2/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
resolver.addArtifactPattern(settings.getBaseDir() + "/test/repositories/m2/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
ModuleRevisionId mrid = ModuleRevisionId.newInstance("org.apache", "mymodule", "myrevision");
Artifact ivyArtifact = new DefaultArtifact(mrid, new Date(), "ivy", "ivy", "xml");
Artifact artifact = new DefaultArtifact(mrid, new Date(), "myartifact", "mytype", "myext");
File src = new File("test/repositories/ivysettings.xml");
resolver.beginPublishTransaction(mrid, false);
// files should not be available until the transaction is committed
resolver.publish(ivyArtifact, src, false);
assertFalse(new File("test/repositories/m2/org/apache/mymodule/myrevision/ivy-myrevision.xml").exists());
resolver.publish(artifact, src, false);
assertFalse(new File("test/repositories/m2/org/apache/mymodule/myrevision/myartifact-myrevision.myext").exists());
resolver.commitPublishTransaction();
assertTrue(new File("test/repositories/m2/org/apache/mymodule/myrevision/ivy-myrevision.xml").exists());
assertTrue(new File("test/repositories/m2/org/apache/mymodule/myrevision/myartifact-myrevision.myext").exists());
}
Aggregations