protected void bootRepackage(final IPackageFragmentRoot[] roots, File packagedFile)
      throws CoreException {
    Repackager bootRepackager = new Repackager(packagedFile);
    try {
      bootRepackager.repackage(
          new Libraries() {

            public void doWithLibraries(LibraryCallback callBack) throws IOException {
              for (IPackageFragmentRoot root : roots) {

                if (root.isArchive()) {

                  File rootFile = new File(root.getPath().toOSString());
                  if (rootFile.exists()) {
                    callBack.library(new Library(rootFile, LibraryScope.COMPILE));
                  }
                }
              }
            }
          });
    } catch (IOException e) {
      handleApplicationDeploymentFailure(
          NLS.bind(Messages.JavaCloudFoundryArchiver_ERROR_REPACKAGE_SPRING, e.getMessage()));
    }
  }
Пример #2
0
  @Override
  public void execute() throws MojoExecutionException, MojoFailureException {
    if (this.project.getPackaging().equals("pom")) {
      getLog().debug("repackage goal could not be applied to pom project.");
      return;
    }
    if (this.skip) {
      getLog().debug("skipping repackaging as per configuration.");
      return;
    }

    File source = this.project.getArtifact().getFile();
    File target = getTargetFile();
    Repackager repackager =
        new Repackager(source) {
          @Override
          protected String findMainMethod(JarFile source) throws IOException {
            long startTime = System.currentTimeMillis();
            try {
              return super.findMainMethod(source);
            } finally {
              long duration = System.currentTimeMillis() - startTime;
              if (duration > FIND_WARNING_TIMEOUT) {
                getLog()
                    .warn(
                        "Searching for the main-class is taking some time, "
                            + "consider using the mainClass configuration "
                            + "parameter");
              }
            }
          }
        };
    repackager.setMainClass(this.mainClass);
    if (this.layout != null) {
      getLog().info("Layout: " + this.layout);
      repackager.setLayout(this.layout.layout());
    }

    Set<Artifact> artifacts = filterDependencies(this.project.getArtifacts(), getFilters());

    Libraries libraries = new ArtifactsLibraries(artifacts, this.requiresUnpack, getLog());
    try {
      LaunchScript launchScript = getLaunchScript();
      repackager.repackage(target, libraries, launchScript);
    } catch (IOException ex) {
      throw new MojoExecutionException(ex.getMessage(), ex);
    }
    if (!source.equals(target)) {
      getLog().info("Attaching archive: " + target + ", with classifier: " + this.classifier);
      this.projectHelper.attachArtifact(
          this.project, this.project.getPackaging(), this.classifier, target);
    }
  }