@Override
 public Result execute(UIExecutionContext context) throws Exception {
   UIContext uiContext = context.getUIContext();
   Project project = (Project) uiContext.getAttributeMap().get(Project.class);
   String coordinate =
       archetypeGroupId.getValue()
           + ":"
           + archetypeArtifactId.getValue()
           + ":"
           + archetypeVersion.getValue();
   DependencyQueryBuilder depQuery = DependencyQueryBuilder.create(coordinate);
   String repository = archetypeRepository.getValue();
   if (repository != null) {
     depQuery.setRepositories(new DependencyRepository("archetype", repository));
   }
   DependencyResolver resolver =
       SimpleContainer.getServices(getClass().getClassLoader(), DependencyResolver.class).get();
   Dependency resolvedArtifact = resolver.resolveArtifact(depQuery);
   FileResource<?> artifact = resolvedArtifact.getArtifact();
   MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
   File fileRoot = project.getRoot().reify(DirectoryResource.class).getUnderlyingResourceObject();
   ArchetypeHelper archetypeHelper =
       new ArchetypeHelper(
           artifact.getResourceInputStream(),
           fileRoot,
           metadataFacet.getProjectGroupName(),
           metadataFacet.getProjectName(),
           metadataFacet.getProjectVersion());
   JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
   archetypeHelper.setPackageName(facet.getBasePackage());
   archetypeHelper.execute();
   return Results.success();
 }
예제 #2
0
 public void extractArtifact(Coordinate artifactCoords, File targetDir)
     throws IOException, DependencyException {
   final DependencyQueryBuilder query = DependencyQueryBuilder.create(artifactCoords);
   Dependency dependency = depsResolver.resolveArtifact(query);
   FileResource<?> artifact = dependency.getArtifact();
   ZipUtil.unzipToFolder(new File(artifact.getFullyQualifiedName()), targetDir);
 }
예제 #3
0
  /** @return Finds the latest non-SNAPSHOT of given artifact. */
  public Coordinate getLatestReleaseOf(final CoordinateBuilder coord) {
    List<Coordinate> availableVersions =
        depsResolver.resolveVersions(DependencyQueryBuilder.create(coord));

    // Find the latest non-SNAPSHOT version.
    for (int i = availableVersions.size() - 1; i >= 0; i--) {
      if (!availableVersions.get(i).isSnapshot()) return availableVersions.get(i);
    }
    return null;
  }
예제 #4
0
 // FIXME
 private Coordinate promptVersion(
     final DependencyFacet deps, final Coordinate dependency, Predicate<Dependency> filter) {
   Coordinate result = dependency;
   final List<Coordinate> versions =
       deps.resolveAvailableVersions(
           DependencyQueryBuilder.create(dependency)
               .setFilter(filter == null ? new NonSnapshotDependencyFilter() : filter));
   if (versions.size() > 0) {
     Coordinate deflt = versions.get(versions.size() - 1);
     result = deflt;
     // result = prompt.promptChoiceTyped("Use which version of '" + dependency.getArtifactId()
     // + "' ?", versions, deflt);
   }
   return result;
 }