private void unpack(File sourceFile, File destDirectory, String type)
      throws MojoExecutionException {
    destDirectory.mkdirs();

    getLog().info("Unpacking (" + type + ") " + sourceFile + " to: " + destDirectory);
    UnArchiver unarchiver;
    try {
      unarchiver = (UnArchiver) plexus.lookup(UnArchiver.ROLE, type);

      unarchiver.setSourceFile(sourceFile);
      unarchiver.setDestDirectory(destDirectory);
      try {
        unarchiver.extract();
      } catch (Exception e) {
        throw new MojoExecutionException("Unable to unpack " + sourceFile, e);
      }
    } catch (ComponentLookupException ce) {
      getLog().warn("Invalid packaging type " + type);

      try {
        FileUtils.copyFileToDirectory(sourceFile, destDirectory);
      } catch (IOException e) {
        throw new MojoExecutionException("Unable to copy " + sourceFile, e);
      }
    }
  }
 private void extractApksources(File apksourcesFile) throws MojoExecutionException {
   if (apksourcesFile.isDirectory()) {
     getLog()
         .warn(
             "The apksources artifact points to '"
                 + apksourcesFile
                 + "' which is a directory; skipping unpacking it.");
     return;
   }
   final UnArchiver unArchiver =
       new ZipUnArchiver(apksourcesFile) {
         @Override
         protected Logger getLogger() {
           return new ConsoleLogger(Logger.LEVEL_DEBUG, "dependencies-unarchiver");
         }
       };
   extractedDependenciesDirectory.mkdirs();
   unArchiver.setDestDirectory(extractedDependenciesDirectory);
   try {
     unArchiver.extract();
   } catch (ArchiverException e) {
     throw new MojoExecutionException(
         "ArchiverException while extracting "
             + apksourcesFile.getAbsolutePath()
             + ". Message: "
             + e.getLocalizedMessage(),
         e);
   }
 }
  /**
   * Unpacks the archive file.
   *
   * @param file File to be unpacked.
   * @param location Location where to put the unpacked files.
   */
  private void unpack(File file, File location)
      throws MojoExecutionException, NoSuchArchiverException {
    String archiveExt = FileUtils.getExtension(file.getAbsolutePath()).toLowerCase();

    try {
      UnArchiver unArchiver = archiverManager.getUnArchiver(archiveExt);
      unArchiver.setSourceFile(file);
      unArchiver.setDestDirectory(location);
      unArchiver.extract();
    } catch (IOException e) {
      throw new MojoExecutionException("Error unpacking file: " + file + "to: " + location, e);
    } catch (ArchiverException e) {
      throw new MojoExecutionException("Error unpacking file: " + file + "to: " + location, e);
    }
  }
 private void unpack(File source, File destination) {
   UnArchiver unzip;
   try {
     unzip = plexus.lookup(UnArchiver.class, "zip");
   } catch (ComponentLookupException e) {
     throw new RuntimeException("Could not lookup required component", e);
   }
   destination.mkdirs();
   unzip.setSourceFile(source);
   unzip.setDestDirectory(destination);
   try {
     unzip.extract();
   } catch (ArchiverException e) {
     throw new RuntimeException("Unable to unpack jar " + source, e);
   }
 }
  /**
   * Unpacks the specified file to the specified directory.
   *
   * @param context the packaging context
   * @param file the file to unpack
   * @param unpackDirectory the directory to use for th unpacked file
   * @throws MojoExecutionException if an error occured while unpacking the file
   */
  protected void doUnpack(AmpPackagingContext context, File file, File unpackDirectory)
      throws MojoExecutionException {
    String archiveExt = FileUtils.getExtension(file.getAbsolutePath()).toLowerCase();

    // Uncompressing an AMP into another AMP does not require any
    // special treatment so we just use a zip unarchiver
    if ("amp".equals(archiveExt)) {
      archiveExt = "zip";
    }

    try {
      UnArchiver unArchiver = context.getArchiverManager().getUnArchiver(archiveExt);
      unArchiver.setSourceFile(file);
      unArchiver.setDestDirectory(unpackDirectory);
      unArchiver.setOverwrite(true);
      unArchiver.extract();
    } catch (IOException e) {
      throw new MojoExecutionException(
          "Error unpacking file["
              + file.getAbsolutePath()
              + "]"
              + "to["
              + unpackDirectory.getAbsolutePath()
              + "]",
          e);
    } catch (ArchiverException e) {
      throw new MojoExecutionException(
          "Error unpacking file["
              + file.getAbsolutePath()
              + "]"
              + "to["
              + unpackDirectory.getAbsolutePath()
              + "]",
          e);
    } catch (NoSuchArchiverException e) {
      context
          .getLog()
          .warn(
              "Skip unpacking dependency file["
                  + file.getAbsolutePath()
                  + " with unknown extension["
                  + archiveExt
                  + "]");
    }
  }
Beispiel #6
0
  // TODO implement at eclipse: have product publisher take the executables from the context
  // repositories
  private File getEquinoxExecutableFeature() throws MojoExecutionException, MojoFailureException {
    // TODO 364134 take the executable feature from the target platform instead
    DependencyArtifacts dependencyArtifacts =
        TychoProjectUtils.getDependencyArtifacts(getProject());
    ArtifactDescriptor artifact =
        dependencyArtifacts.getArtifact(
            ArtifactType.TYPE_ECLIPSE_FEATURE, "org.eclipse.equinox.executable", null);

    if (artifact == null) {
      throw new MojoExecutionException(
          "Unable to locate the equinox launcher feature (aka delta-pack)");
    }

    File equinoxExecFeature = artifact.getLocation();
    if (equinoxExecFeature.isDirectory()) {
      return equinoxExecFeature.getAbsoluteFile();
    } else {
      File unzipped =
          new File(
              getProject().getBuild().getDirectory(),
              artifact.getKey().getId() + "-" + artifact.getKey().getVersion());
      if (unzipped.exists()) {
        return unzipped.getAbsoluteFile();
      }
      try {
        FileLocker locker = fileLockService.getFileLocker(equinoxExecFeature);
        locker.lock();
        try {
          // unzip now then:
          unzipped.mkdirs();
          deflater.setSourceFile(equinoxExecFeature);
          deflater.setDestDirectory(unzipped);
          deflater.extract();
          return unzipped.getAbsoluteFile();
        } finally {
          locker.release();
        }
      } catch (ArchiverException e) {
        throw new MojoFailureException("Unable to unzip the eqiuinox executable feature", e);
      }
    }
  }
  private void addFilteredUnpackedArtifact(
      final DependencySet dependencySet,
      final Artifact depArtifact,
      final MavenProject depProject,
      final Archiver archiver,
      final AssemblerConfigurationSource configSource)
      throws ArchiveCreationException, AssemblyFormattingException {
    logger.debug(
        "Adding dependency artifact "
            + depArtifact.getId()
            + " after filtering the unpacked contents.");

    final StringBuilder sb =
        new StringBuilder()
            .append(depArtifact.getGroupId())
            .append("_")
            .append(depArtifact.getArtifactId())
            .append("_")
            .append(depArtifact.getVersion());

    final String classifier = depArtifact.getClassifier();
    if (classifier != null) {
      sb.append("_").append(classifier);
    }

    sb.append(".").append(depArtifact.getType());

    final File dir = new File(configSource.getWorkingDirectory(), sb.toString());
    if (dir.exists()) {
      logger.debug(
          "NOT unpacking: "
              + depArtifact.getId()
              + ". Directory already exists in workdir:\n\t"
              + dir.getAbsolutePath());
    } else {
      dir.mkdirs();

      UnArchiver unarchiver;
      try {
        unarchiver = archiverManager.getUnArchiver(depArtifact.getFile());
      } catch (final NoSuchArchiverException e) {
        throw new ArchiveCreationException(
            "Failed to retrieve un-archiver for: "
                + depArtifact.getId()
                + ". Dependency filtering cannot proceed.",
            e);
      }

      unarchiver.setDestDirectory(dir);
      unarchiver.setOverwrite(true);
      unarchiver.setSourceFile(depArtifact.getFile());
      unarchiver.setIgnorePermissions(configSource.isIgnorePermissions());

      try {
        unarchiver.extract();
      } catch (final ArchiverException e) {
        throw new ArchiveCreationException(
            "Failed to unpack dependency archive: "
                + depArtifact.getId()
                + ". Dependency filtering cannot proceed.",
            e);
      }
    }

    final UnpackOptions opts = dependencySet.getUnpackOptions();

    final FileSet fs = new FileSet();
    fs.setDirectory(dir.getAbsolutePath());
    fs.setDirectoryMode(dependencySet.getDirectoryMode());
    fs.setExcludes(opts.getExcludes());
    fs.setFileMode(dependencySet.getFileMode());
    fs.setFiltered(opts.isFiltered());
    fs.setIncludes(opts.getIncludes());

    String outDir = dependencySet.getOutputDirectory();
    if (outDir == null) {
      outDir = defaultOutputDirectory;
    }

    String filenameMapping = dependencySet.getOutputFileNameMapping();
    if (filenameMapping == null) {
      filenameMapping = defaultOutputFileNameMapping;
    }

    filenameMapping =
        AssemblyFormatUtils.evaluateFileNameMapping(
            filenameMapping,
            depArtifact,
            configSource.getProject(),
            moduleProject,
            moduleArtifact,
            depProject,
            configSource);

    final String outputLocation = new File(outDir, filenameMapping).getPath();

    fs.setOutputDirectory(outputLocation);

    fs.setLineEnding(opts.getLineEnding());
    fs.setUseDefaultExcludes(opts.isUseDefaultExcludes());

    final AddFileSetsTask task = new AddFileSetsTask(fs);
    task.setProject(depProject);
    task.setModuleProject(moduleProject);
    task.setLogger(logger);

    task.execute(archiver, configSource);
  }
Beispiel #8
0
  private synchronized void initialize() {
    if (eclipse != null) {
      return;
    }
    final File p2BridgePluginDir = getP2BridgePluginDir();
    final File p2BridgeRuntimeDir =
        new File(
            applicationConfiguration.getTemporaryDirectory(), "nexus-p2-bridge-plugin/runtime");
    final File p2BridgeTempDir =
        new File(applicationConfiguration.getTemporaryDirectory(), "nexus-p2-bridge-plugin/tmp");
    final File eclipseDir = new File(p2BridgeRuntimeDir, "eclipse");

    // if temporary plugin directory exists, remove it to avoid the fact that eclipse stores
    // absolute paths to
    // installed bundles (see NXCM-4475)
    try {
      DirSupport.deleteIfExists(p2BridgeRuntimeDir.toPath());
    } catch (IOException e) {
      throw new RuntimeException(
          "Cannot delete nexus-p2-bridge temporary directory "
              + p2BridgeRuntimeDir.getAbsolutePath(),
          e);
    }
    try {
      DirSupport.mkdir(p2BridgeRuntimeDir.toPath());
    } catch (IOException e) {
      throw new RuntimeException(
          "Cannot create nexus-p2-bridge temporary directory "
              + p2BridgeRuntimeDir.getAbsolutePath(),
          e);
    }
    // create a fresh eclipse instance
    try {
      unArchiver.setSourceFile(new File(p2BridgePluginDir, "p2-runtime/eclipse.zip"));
      unArchiver.setDestDirectory(p2BridgeRuntimeDir);
      unArchiver.extract();
    } catch (final Exception e) {
      throw new RuntimeException("Cannot unpack Eclipse", e);
    }

    final EclipseLocation eclipseLocation =
        eclipseLocationFactory.createStaticEclipseLocation(eclipseDir);

    eclipse = eclipseBridge.createInstance(eclipseLocation);
    try {
      {
        // TODO is this really necessary?
        final File secureStorage =
            new File(
                applicationConfiguration.getConfigurationDirectory(), "eclipse.secure_storage");
        if (secureStorage.exists() && !secureStorage.delete()) {
          throw new RuntimeException(
              "Could not delete Eclipse secure storage " + secureStorage.getAbsolutePath());
        }
        EclipseEnvironmentInfo.setAppArgs(
            new String[] {"-eclipse.keyring", secureStorage.getAbsolutePath()});
      }
      eclipse.start(initParams(p2BridgePluginDir, eclipseDir, p2BridgeTempDir));
      final File[] bundles =
          new File(p2BridgePluginDir, "p2-runtime/bundles")
              .listFiles(
                  new FilenameFilter() {
                    @Override
                    public boolean accept(final File dir, final String name) {
                      return name.endsWith(".jar");
                    }
                  });
      for (final File bundle : bundles) {
        eclipse.startBundle(eclipse.installBundle(bundle.toURI().toASCIIString()));
      }
    } catch (final Exception e) {
      throw new RuntimeException(e);
    }
  }
  protected void unpackNarAndProcess(
      ArchiverManager archiverManager,
      File file,
      File narLocation,
      String os,
      String linkerName,
      AOL defaultAOL)
      throws MojoExecutionException, MojoFailureException {

    final String gpp = "g++";
    final String gcc = "gcc";

    narLocation.mkdirs();

    // unpack
    try {
      UnArchiver unArchiver;
      unArchiver = archiverManager.getUnArchiver(NarConstants.NAR_ROLE_HINT);
      unArchiver.setSourceFile(file);
      unArchiver.setDestDirectory(narLocation);
      unArchiver.extract();
    } catch (NoSuchArchiverException e) {
      throw new MojoExecutionException("Error unpacking file: " + file + " to: " + narLocation, e);
    } catch (ArchiverException e) {
      throw new MojoExecutionException("Error unpacking file: " + file + " to: " + narLocation, e);
    }

    // process
    if (!NarUtil.getOS(os).equals(OS.WINDOWS)) {
      NarUtil.makeExecutable(new File(narLocation, "bin/" + defaultAOL), log);
      // FIXME clumsy
      if (defaultAOL.hasLinker(gpp)) {
        NarUtil.makeExecutable(
            new File(narLocation, "bin/" + NarUtil.replace(gpp, gcc, defaultAOL.toString())), log);
      }
      // add link to versioned so files
      NarUtil.makeLink(new File(narLocation, "lib/" + defaultAOL), log);
    }
    if (linkerName.equals(gcc) || linkerName.equals(gpp)) {
      NarUtil.runRanlib(new File(narLocation, "lib/" + defaultAOL), log);
      // FIXME clumsy
      if (defaultAOL.hasLinker(gpp)) {
        NarUtil.runRanlib(
            new File(narLocation, "lib/" + NarUtil.replace(gpp, gcc, defaultAOL.toString())), log);
      }
    }
    // TODO: Find replacement action to install name tool
    // install name tool adjusts the internal lookup directory for the libraries,
    // this isn't really appropriate, removing signatures for one.
    // however don't have a replacement action currently... having commented this,
    // may break some usage, perhaps if don't find solution make configurable.
    //        if ( NarUtil.getOS( os ).equals( OS.MACOSX ) )
    //        {
    //            File[] dylibDirs = new File[2];
    //            dylibDirs[0] = new File( narLocation, "lib/" + defaultAOL + "/" + Library.SHARED
    // );
    //            dylibDirs[1] = new File( narLocation, "lib/" + defaultAOL + "/" + Library.JNI );
    //
    //            NarUtil.runInstallNameTool( dylibDirs, log );
    //        }
  }