org.eclipse.aether.util.artifact.SubArtifact Java Examples

The following examples show how to use org.eclipse.aether.util.artifact.SubArtifact. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Publisher.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * @param descriptor an {@link Artifact}, holding the maven coordinates for the published files
 *     less the extension that is to be derived from the files. The {@code descriptor} itself will
 *     not be published as is, and the {@link File} attached to it (if any) will be ignored.
 * @param toPublish {@link File}(s) to be published using the given coordinates. The filename
 *     extension of each given file will be used as a maven "extension" coordinate
 */
public DeployResult publish(Artifact descriptor, List<File> toPublish)
    throws DeploymentException {
  String providedExtension = descriptor.getExtension();
  if (!providedExtension.isEmpty()) {
    LOG.warn(
        "Provided extension %s of artifact %s to be published will be ignored. The extensions "
            + "of the provided file(s) will be used",
        providedExtension, descriptor);
  }
  List<Artifact> artifacts = new ArrayList<>(toPublish.size());
  for (File file : toPublish) {
    artifacts.add(
        new SubArtifact(
            descriptor,
            descriptor.getClassifier(),
            Files.getFileExtension(file.getAbsolutePath()),
            file));
  }
  return publish(artifacts);
}
 
Example #2
Source File: MavenTest.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testMvn1 () throws Exception
{
    final ChannelTester ct = ChannelTester.create ( getWebContext (), "m1" );
    ct.addAspect ( "mvn" );
    ct.addAspect ( "maven.repo" );
    ct.assignDeployGroup ( "m1" );

    final String key = ct.getDeployKeys ().iterator ().next (); // get first

    assertNotNull ( key );

    final RepositorySystem system = MavenUtil.newRepositorySystem ();
    final RepositorySystemSession session = MavenUtil.newRepositorySystemSession ( system );

    Artifact jarArtifact = new DefaultArtifact ( "org.eclipse.packagedrone.testing", "test.felix1", "", "jar", "0.0.1-SNAPSHOT" );
    jarArtifact = jarArtifact.setFile ( new File ( TEST_1_JAR ) );

    Artifact pomArtifact = new SubArtifact ( jarArtifact, "", "pom" );
    pomArtifact = pomArtifact.setFile ( new File ( TEST_1_POM ) );

    Artifact srcArtifact = new SubArtifact ( jarArtifact, "sources", "jar" );
    srcArtifact = srcArtifact.setFile ( new File ( TEST_1_SOURCES_JAR ) );

    final AuthenticationBuilder ab = new AuthenticationBuilder ();
    ab.addUsername ( "deploy" );
    ab.addPassword ( key );
    final Authentication auth = ab.build ();
    final RemoteRepository distRepo = new RemoteRepository.Builder ( "test", "default", resolve ( String.format ( "/maven/%s", ct.getId () ) ) ).setAuthentication ( auth ).build ();

    final DeployRequest deployRequest = new DeployRequest ();
    deployRequest.addArtifact ( jarArtifact ).addArtifact ( pomArtifact ).addArtifact ( srcArtifact );
    deployRequest.setRepository ( distRepo );

    system.deploy ( session, deployRequest );

    testUrl ( String.format ( "/maven/%s", ct.getId () ) ); // index page

    // FIXME: check more data
}
 
Example #3
Source File: Resolver.java    From buck with Apache License 2.0 5 votes vote down vote up
private void downloadSources(Artifact artifact, Path project, Prebuilt library)
    throws IOException {
  Artifact srcs = new SubArtifact(artifact, "sources", "jar");
  try {
    Path relativePath = resolveArtifact(srcs, project);
    library.setSourceJar(relativePath);
  } catch (ArtifactResolutionException e) {
    System.err.println("Skipping sources for: " + srcs);
  }
}
 
Example #4
Source File: MavenPluginUtil.java    From galleon with Apache License 2.0 4 votes vote down vote up
public InstallRequest getInstallLayoutRequest(final Path layoutDir, final MavenProject project) throws IOException {
    final File pomFile = project.getFile();
    final Logger logger = getLogger();
    final InstallRequest installReq = new InstallRequest();
    try (DirectoryStream<Path> wdStream = Files.newDirectoryStream(layoutDir, entry -> Files.isDirectory(entry))) {
        for (Path groupDir : wdStream) {
            final String groupId = groupDir.getFileName().toString();
            try (DirectoryStream<Path> groupStream = Files.newDirectoryStream(groupDir)) {
                for (Path artifactDir : groupStream) {
                    final String artifactId = artifactDir.getFileName().toString();
                    try (DirectoryStream<Path> artifactStream = Files.newDirectoryStream(artifactDir)) {
                        for (Path versionDir : artifactStream) {
                            if(logger.isDebugEnabled()) {
                                logger.debug("Preparing feature-pack " + versionDir.toAbsolutePath());
                            }
                            final Path zippedFP = layoutDir.resolve(
                                    groupId + '_' + artifactId + '_' + versionDir.getFileName().toString() + ".zip");
                            if(Files.exists(zippedFP)) {
                                IoUtils.recursiveDelete(zippedFP);
                            }
                            ZipUtils.zip(versionDir, zippedFP);
                            final Artifact artifact = new DefaultArtifact(
                                    groupDir.getFileName().toString(),
                                    artifactDir.getFileName().toString(), null,
                                    "zip", versionDir.getFileName().toString(), null, zippedFP.toFile());
                            Path target = Paths.get(project.getBuild().getDirectory()).resolve(project.getBuild().getFinalName() + ".zip");
                            IoUtils.copy(zippedFP, target);
                            installReq.addArtifact(artifact);
                            if (pomFile != null && Files.exists(pomFile.toPath())) {
                                Artifact pomArtifact = new SubArtifact(artifact, "", "pom");
                                pomArtifact = pomArtifact.setFile(pomFile);
                                installReq.addArtifact(pomArtifact);
                            }
                        }
                    }
                }
            }
        }
    }
    return installReq;
}