use of org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout in project intellij-community by JetBrains.
the class Maven2ServerEmbedderImpl method retrieveAvailableVersions.
@NotNull
@Override
public List<String> retrieveAvailableVersions(@NotNull String groupId, @NotNull String artifactId, @NotNull List<MavenRemoteRepository> remoteRepositories) throws RemoteException {
try {
Artifact artifact = new DefaultArtifact(groupId, artifactId, VersionRange.createFromVersion(""), Artifact.SCOPE_COMPILE, "pom", null, new DefaultArtifactHandler("pom"));
ArtifactRepositoryLayout repositoryLayout = getComponent(ArtifactRepositoryLayout.class);
List versions = getComponent(ArtifactMetadataSource.class).retrieveAvailableVersions(artifact, new DefaultArtifactRepository("local", getLocalRepositoryFile().getPath(), repositoryLayout), convertRepositories(remoteRepositories));
List<String> result = new ArrayList<String>();
for (Object version : versions) {
result.add(version.toString());
}
return result;
} catch (Exception e) {
Maven2ServerGlobals.getLogger().info(e);
}
return Collections.emptyList();
}
use of org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout in project intellij-community by JetBrains.
the class MavenEmbedder method createLocalRepository.
private ArtifactRepository createLocalRepository(MavenEmbedderSettings generalSettings) {
ArtifactRepositoryLayout layout = getComponent(ArtifactRepositoryLayout.class, "default");
ArtifactRepositoryFactory factory = getComponent(ArtifactRepositoryFactory.class);
String url = mySettings.getLocalRepository();
if (!url.startsWith("file:"))
url = "file://" + url;
ArtifactRepository localRepository = new DefaultArtifactRepository("local", url, layout);
boolean snapshotPolicySet = mySettings.isOffline();
if (!snapshotPolicySet && generalSettings.getSnapshotUpdatePolicy() == MavenEmbedderSettings.UpdatePolicy.ALWAYS_UPDATE) {
factory.setGlobalUpdatePolicy(ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS);
}
factory.setGlobalChecksumPolicy(ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
return localRepository;
}
use of org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout in project karaf by apache.
the class KarMojo method createArchive.
/**
* Generates the configuration archive.
*
* @param bundles
*/
@SuppressWarnings("deprecation")
private File createArchive(List<Artifact> bundles, File featuresFile, String groupId, String artifactId, String version) throws MojoExecutionException {
ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
File archiveFile = getArchiveFile(outputDirectory, finalName, classifier);
MavenArchiver archiver = new MavenArchiver();
MavenArchiveConfiguration configuration = new MavenArchiveConfiguration();
configuration.addManifestEntries(archive.getManifestEntries());
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(archiveFile);
try {
//TODO should .kar be a bundle?
// archive.addManifestEntry(Constants.BUNDLE_NAME, project.getName());
// archive.addManifestEntry(Constants.BUNDLE_VENDOR, project.getOrganization().getName());
// ArtifactVersion version = project.getArtifact().getSelectedVersion();
// String versionString = "" + version.getMajorVersion() + "." + version.getMinorVersion() + "." + version.getIncrementalVersion();
// if (version.getQualifier() != null) {
// versionString += "." + version.getQualifier();
// }
// archive.addManifestEntry(Constants.BUNDLE_VERSION, versionString);
// archive.addManifestEntry(Constants.BUNDLE_MANIFESTVERSION, "2");
// archive.addManifestEntry(Constants.BUNDLE_DESCRIPTION, project.getDescription());
// // NB, no constant for this one
// archive.addManifestEntry("Bundle-License", ((License) project.getLicenses().get(0)).getUrl());
// archive.addManifestEntry(Constants.BUNDLE_DOCURL, project.getUrl());
// //TODO this might need some help
// archive.addManifestEntry(Constants.BUNDLE_SYMBOLICNAME, project.getArtifactId());
//include the feature.xml
Artifact featureArtifact = factory.createArtifactWithClassifier(groupId, artifactId, version, "xml", KarArtifactInstaller.FEATURE_CLASSIFIER);
jarArchiver.addFile(featuresFile, repositoryPath + layout.pathOf(featureArtifact));
if (featureArtifact.isSnapshot()) {
// the artifact is a snapshot, create the maven-metadata-local.xml
getLog().debug("Feature artifact is a SNAPSHOT, handling the maven-metadata-local.xml");
File metadataTarget = new File(featuresFile.getParentFile(), "maven-metadata-local.xml");
getLog().debug("Looking for " + metadataTarget.getAbsolutePath());
if (!metadataTarget.exists()) {
// the maven-metadata-local.xml doesn't exist, create it
getLog().debug(metadataTarget.getAbsolutePath() + " doesn't exist, create it");
Metadata metadata = new Metadata();
metadata.setGroupId(featureArtifact.getGroupId());
metadata.setArtifactId(featureArtifact.getArtifactId());
metadata.setVersion(featureArtifact.getVersion());
metadata.setModelVersion("1.1.0");
Versioning versioning = new Versioning();
versioning.setLastUpdatedTimestamp(new Date(System.currentTimeMillis()));
Snapshot snapshot = new Snapshot();
snapshot.setLocalCopy(true);
versioning.setSnapshot(snapshot);
SnapshotVersion snapshotVersion = new SnapshotVersion();
snapshotVersion.setClassifier(featureArtifact.getClassifier());
snapshotVersion.setVersion(featureArtifact.getVersion());
snapshotVersion.setExtension(featureArtifact.getType());
snapshotVersion.setUpdated(versioning.getLastUpdated());
versioning.addSnapshotVersion(snapshotVersion);
metadata.setVersioning(versioning);
MetadataXpp3Writer metadataWriter = new MetadataXpp3Writer();
try {
Writer writer = new FileWriter(metadataTarget);
metadataWriter.write(writer, metadata);
} catch (Exception e) {
getLog().warn("Could not create maven-metadata-local.xml", e);
getLog().warn("It means that this SNAPSHOT could be overwritten by an older one present on remote repositories");
}
}
getLog().debug("Adding file " + metadataTarget.getAbsolutePath() + " in the jar path " + repositoryPath + layout.pathOf(featureArtifact).substring(0, layout.pathOf(featureArtifact).lastIndexOf('/')) + "/maven-metadata-local.xml");
jarArchiver.addFile(metadataTarget, repositoryPath + layout.pathOf(featureArtifact).substring(0, layout.pathOf(featureArtifact).lastIndexOf('/')) + "/maven-metadata-local.xml");
}
for (Artifact artifact : bundles) {
artifactResolver.resolve(artifact, remoteRepos, localRepo);
//TODO this may not be reasonable, but... resolved snapshot artifacts have timestamped versions
//which do not work in startup.properties.
artifact.setVersion(artifact.getBaseVersion());
if (artifact.isSnapshot()) {
// the artifact is a snapshot, create the maven-metadata-local.xml
final File metadataTmp = File.createTempFile("maven-metadata-local.xml", ".tmp");
try {
MavenUtil.generateMavenMetadata(artifact, metadataTmp);
} catch (Exception e) {
getLog().warn("Could not create maven-metadata-local.xml", e);
getLog().warn("It means that this SNAPSHOT could be overwritten by an older one present on remote repositories");
}
jarArchiver.addFile(metadataTmp, repositoryPath + layout.pathOf(artifact).substring(0, layout.pathOf(artifact).lastIndexOf('/')) + "/maven-metadata-local.xml");
try {
metadataTmp.delete();
} catch (final Exception ex) {
getLog().warn("Cannot delete temporary created file.", ex);
}
}
String targetFileName = repositoryPath + layout.pathOf(artifact);
jarArchiver.addFile(artifact.getFile(), targetFileName);
}
if (resourcesDir.isDirectory()) {
archiver.getArchiver().addDirectory(resourcesDir);
}
archiver.createArchive(project, archive);
return archiveFile;
} catch (Exception e) {
throw new MojoExecutionException("Failed to create archive", e);
}
}
use of org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout in project maven-plugins by apache.
the class GetMojo method parseRepository.
ArtifactRepository parseRepository(String repo, ArtifactRepositoryPolicy policy) throws MojoFailureException {
// if it's a simple url
String id = "temp";
ArtifactRepositoryLayout layout = getLayout("default");
String url = repo;
// if it's an extended repo URL of the form id::layout::url
if (repo.contains("::")) {
Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher(repo);
if (!matcher.matches()) {
throw new MojoFailureException(repo, "Invalid syntax for repository: " + repo, "Invalid syntax for repository. Use \"id::layout::url\" or \"URL\".");
}
id = matcher.group(1).trim();
if (!StringUtils.isEmpty(matcher.group(2))) {
layout = getLayout(matcher.group(2).trim());
}
url = matcher.group(3).trim();
}
return new MavenArtifactRepository(id, url, layout, policy, policy);
}
use of org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout in project maven-plugins by apache.
the class SignAndDeployFileMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
AbstractGpgSigner signer = newSigner(null);
signer.setOutputDirectory(ascDirectory);
signer.setBaseDirectory(new File("").getAbsoluteFile());
if (offline) {
throw new MojoFailureException("Cannot deploy artifacts when Maven is in offline mode");
}
initProperties();
validateArtifactInformation();
if (!file.exists()) {
throw new MojoFailureException(file.getPath() + " not found.");
}
ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) repositoryLayouts.get(repositoryLayout);
if (layout == null) {
throw new MojoFailureException("Invalid repository layout: " + repositoryLayout);
}
ArtifactRepository deploymentRepository = repositoryFactory.createDeploymentArtifactRepository(repositoryId, url, layout, uniqueVersion);
if (StringUtils.isEmpty(deploymentRepository.getProtocol())) {
throw new MojoFailureException("No transfer protocol found.");
}
Artifact artifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, packaging, classifier);
if (file.equals(getLocalRepoFile(artifact))) {
throw new MojoFailureException("Cannot deploy artifact from the local repository: " + file);
}
File fileSig = signer.generateSignatureForArtifact(file);
ArtifactMetadata metadata = new AscArtifactMetadata(artifact, fileSig, false);
artifact.addMetadata(metadata);
if (!"pom".equals(packaging)) {
if (pomFile == null && generatePom) {
pomFile = generatePomFile();
}
if (pomFile != null) {
metadata = new ProjectArtifactMetadata(artifact, pomFile);
artifact.addMetadata(metadata);
fileSig = signer.generateSignatureForArtifact(pomFile);
metadata = new AscArtifactMetadata(artifact, fileSig, true);
artifact.addMetadata(metadata);
}
}
if (updateReleaseInfo) {
artifact.setRelease(true);
}
project.setArtifact(artifact);
try {
deploy(file, artifact, deploymentRepository, localRepository);
} catch (ArtifactDeploymentException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
if (sources != null) {
projectHelper.attachArtifact(project, "jar", "sources", sources);
}
if (javadoc != null) {
projectHelper.attachArtifact(project, "jar", "javadoc", javadoc);
}
if (files != null) {
if (types == null) {
throw new MojoExecutionException("You must specify 'types' if you specify 'files'");
}
if (classifiers == null) {
throw new MojoExecutionException("You must specify 'classifiers' if you specify 'files'");
}
int filesLength = StringUtils.countMatches(files, ",");
int typesLength = StringUtils.countMatches(types, ",");
int classifiersLength = StringUtils.countMatches(classifiers, ",");
if (typesLength != filesLength) {
throw new MojoExecutionException("You must specify the same number of entries in 'files' and " + "'types' (respectively " + filesLength + " and " + typesLength + " entries )");
}
if (classifiersLength != filesLength) {
throw new MojoExecutionException("You must specify the same number of entries in 'files' and " + "'classifiers' (respectively " + filesLength + " and " + classifiersLength + " entries )");
}
int fi = 0;
int ti = 0;
int ci = 0;
for (int i = 0; i <= filesLength; i++) {
int nfi = files.indexOf(',', fi);
if (nfi == -1) {
nfi = files.length();
}
int nti = types.indexOf(',', ti);
if (nti == -1) {
nti = types.length();
}
int nci = classifiers.indexOf(',', ci);
if (nci == -1) {
nci = classifiers.length();
}
File file = new File(files.substring(fi, nfi));
if (!file.isFile()) {
// try relative to the project basedir just in case
file = new File(project.getBasedir(), files.substring(fi, nfi));
}
if (file.isFile()) {
if (StringUtils.isWhitespace(classifiers.substring(ci, nci))) {
projectHelper.attachArtifact(project, types.substring(ti, nti).trim(), file);
} else {
projectHelper.attachArtifact(project, types.substring(ti, nti).trim(), classifiers.substring(ci, nci).trim(), file);
}
} else {
throw new MojoExecutionException("Specified side artifact " + file + " does not exist");
}
fi = nfi + 1;
ti = nti + 1;
ci = nci + 1;
}
} else {
if (types != null) {
throw new MojoExecutionException("You must specify 'files' if you specify 'types'");
}
if (classifiers != null) {
throw new MojoExecutionException("You must specify 'files' if you specify 'classifiers'");
}
}
List attachedArtifacts = project.getAttachedArtifacts();
for (Object attachedArtifact : attachedArtifacts) {
Artifact attached = (Artifact) attachedArtifact;
fileSig = signer.generateSignatureForArtifact(attached.getFile());
attached = new AttachedSignedArtifact(attached, new AscArtifactMetadata(attached, fileSig, false));
try {
deploy(attached.getFile(), attached, deploymentRepository, localRepository);
} catch (ArtifactDeploymentException e) {
throw new MojoExecutionException("Error deploying attached artifact " + attached.getFile() + ": " + e.getMessage(), e);
}
}
}
Aggregations