Package org.eclipse.jdt.ui.jarpackager

Examples of org.eclipse.jdt.ui.jarpackager.JarPackageData


      if (roots == null || roots.length == 0) {
        handleApplicationDeploymentFailure(Messages.JavaCloudFoundryArchiver_ERROR_NO_PACKAGE_FRAG_ROOTS);
      }

      JarPackageData jarPackageData = getJarPackageData(roots, mainType,
          monitor);

      boolean isBoot = isBootProject(javaProject);

      // Search for existing MANIFEST.MF
      IFile metaFile = getManifest(roots, javaProject);

      // Only use existing manifest files for non-Spring boot, as Spring
      // boot repackager will
      // generate it own manifest file.
      if (!isBoot && metaFile != null) {
        // If it is not a boot project, use a standard library jar
        // builder
        jarPackageData.setJarBuilder(getDefaultLibJarBuilder());

        jarPackageData.setManifestLocation(metaFile.getFullPath());
        jarPackageData.setSaveManifest(false);
        jarPackageData.setGenerateManifest(false);
        // Check manifest accessibility through the jar package data
        // API
        // to verify the packaging won't fail
        if (!jarPackageData.isManifestAccessible()) {
          handleApplicationDeploymentFailure(NLS
              .bind(Messages.JavaCloudFoundryArchiver_ERROR_MANIFEST_NOT_ACCESSIBLE,
                  metaFile.getLocation().toString()));
        }

        InputStream inputStream = null;
        try {

          inputStream = new FileInputStream(metaFile.getLocation()
              .toFile());
          Manifest manifest = new Manifest(inputStream);
          Attributes att = manifest.getMainAttributes();
          if (att.getValue("Main-Class") == null) { //$NON-NLS-1$
            handleApplicationDeploymentFailure(Messages.JavaCloudFoundryArchiver_ERROR_NO_MAIN_CLASS_IN_MANIFEST);
          }
        } catch (FileNotFoundException e) {
          handleApplicationDeploymentFailure(NLS
              .bind(Messages.JavaCloudFoundryArchiver_ERROR_FAILED_READ_MANIFEST,
                  e.getLocalizedMessage()));

        } catch (IOException e) {
          handleApplicationDeploymentFailure(NLS
              .bind(Messages.JavaCloudFoundryArchiver_ERROR_FAILED_READ_MANIFEST,
                  e.getLocalizedMessage()));

        } finally {

          if (inputStream != null) {
            try {
              inputStream.close();

            } catch (IOException io) {
              // Ignore
            }
          }
        }

      } else {
        // Otherwise generate a manifest file. Note that manifest files
        // are only generated in the temporary jar meant only for
        // deployment.
        // The associated Java project is no modified.
        jarPackageData.setGenerateManifest(true);

        // This ensures that folders in output folders appear at root
        // level
        // Example: src/main/resources, which is in the project's
        // classpath, contains non-Java templates folder and
        // has output folder target/classes. If not exporting output
        // folder,
        // templates will be packaged in the jar using this path:
        // resources/templates
        // This may cause problems with the application's dependencies
        // if they are looking for just /templates at top level of the
        // jar
        // If exporting output folders, templates folder will be
        // packaged at top level in the jar.
        jarPackageData.setExportOutputFolders(true);
      }

      try {
        packagedFile = packageApplication(jarPackageData, monitor);
      } catch (CoreException e) {
View Full Code Here


    IPath location = new Path(filePath);

    // Note that if no jar builder is specified in the package data
    // then a default one is used internally by the data that does NOT
    // package any jar dependencies.
    JarPackageData packageData = new JarPackageData();

    packageData.setJarLocation(location);

    // Don't create a manifest. A repackager should determine if a generated
    // manifest is necessary
    // or use a user-defined manifest.
    packageData.setGenerateManifest(false);

    // Since user manifest is not used, do not save to manifest (save to
    // manifest saves to user defined manifest)
    packageData.setSaveManifest(false);

    packageData.setManifestMainClass(mainType);
    packageData.setElements(roots);
    return packageData;
  }
View Full Code Here

  /**
   * Create the jar file containing all the MapReduce job classes.
   */
  public File buildJar(IProgressMonitor monitor) {
    log.fine("Build jar");
    JarPackageData jarrer = new JarPackageData();

    jarrer.setExportJavaFiles(true);
    jarrer.setExportClassFiles(true);
    jarrer.setExportOutputFolders(true);
    jarrer.setOverwrite(true);

    Path path;

    try {
      IJavaProject project = (IJavaProject) resource.getProject().getNature(
          JavaCore.NATURE_ID); // todo(jz)
      // check this is the case before letting this method get called
      Object element = resource.getAdapter(IJavaElement.class);
      IType type = ((ICompilationUnit) element).findPrimaryType();
      jarrer.setManifestMainClass(type);
      path = new Path(new File(Activator.getDefault().getStateLocation()
          .toFile(), resource.getProject().getName() + "_project_hadoop_"
          + resource.getName() + "_" + System.currentTimeMillis() + ".jar")
          .getAbsolutePath());
      jarrer.setJarLocation(path);

      jarrer.setElements(resource.getProject().members(IResource.FILE));
      IJarExportRunnable runnable = jarrer.createJarExportRunnable(null);
      runnable.run(monitor);
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
View Full Code Here

   * @return a file designing the created package
   */
  public void run(IProgressMonitor monitor) {

    log.fine("Build jar");
    JarPackageData jarrer = new JarPackageData();

    jarrer.setExportJavaFiles(true);
    jarrer.setExportClassFiles(true);
    jarrer.setExportOutputFolders(true);
    jarrer.setOverwrite(true);

    try {
      // IJavaProject project =
      // (IJavaProject) resource.getProject().getNature(JavaCore.NATURE_ID);

      // check this is the case before letting this method get called
      Object element = resource.getAdapter(IJavaElement.class);
      IType type = ((ICompilationUnit) element).findPrimaryType();
      jarrer.setManifestMainClass(type);

      // Create a temporary JAR file name
      File baseDir = Activator.getDefault().getStateLocation().toFile();

      String prefix =
          String.format("%s_%s-", resource.getProject().getName(), resource
              .getName());
      File jarFile = File.createTempFile(prefix, ".jar", baseDir);
      jarrer.setJarLocation(new Path(jarFile.getAbsolutePath()));

      jarrer.setElements(resource.getProject().members(IResource.FILE));
      IJarExportRunnable runnable =
          jarrer.createJarExportRunnable(Display.getDefault()
              .getActiveShell());
      runnable.run(monitor);

      this.jarFile = jarFile;

View Full Code Here

      }});
   
    for (int i = 0; i < jardescs.size(); i++)
    {
      IFile jardesc = (IFile) jardescs.get(i);
      JarPackageData jarPackage = new JarPackageData();
      IJarDescriptionReader reader = jarPackage.createJarDescriptionReader(jardesc.getContents());
      reader.read(jarPackage);
      jarPackage.setSaveManifest(false);
      jarPackage.setSaveDescription(false);
      jarPackage.setOverwrite(true);
      jarPackage.setBuildIfNeeded(false);
      IPath path = jarPackage.getJarLocation();
      if (path.segmentCount() > 1)
      {
        jarPackage.setJarLocation(path.removeFirstSegments(path.segmentCount() - 1));
      }
      SysOutProgressMonitor.out.println("Exporting jar file using jar descriptor: " + jardesc.getFullPath() + " to: " + jarPackage.getAbsoluteJarLocation().toOSString());
      IJarExportRunnable export = jarPackage.createJarExportRunnable(null);
      export.run(monitor);
      SysOutProgressMonitor.out.println();
    }
  }
View Full Code Here

      IFile cdkProjectJarFile = project.getFile(cdkProjectJarLocation.lastSegment());
     
      ResourceUtils.createDirectory(ResourceUtils.getDirectory(cdkProjectJarLocation.toFile()));
     
      monitor.setTaskName("Initializing Jar ...");
      JarPackageData jarPackageData = new JarPackageData();
      jarPackageData.setElements(new Object[] { project });
      jarPackageData.setExportClassFiles(false);
      jarPackageData.setExportOutputFolders(true);
      jarPackageData.setExportJavaFiles(false);
      jarPackageData.setExportErrors(false);
      jarPackageData.setExportWarnings(false);
      jarPackageData.setRefactoringAware(false);
      jarPackageData.setCompress(true);
      jarPackageData.setIncludeDirectoryEntries(false);
      jarPackageData.setOverwrite(true);
      jarPackageData.setJarLocation(cdkProjectJarLocation);
      monitor.worked(5);
     
      monitor.setTaskName("Creating Connector Jar ...");
      new JarFileExportOperation(jarPackageData, PlatformUI.createDisplay().getActiveShell()).run(new SubProgressMonitor(monitor, 100, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
      cdkProjectJarFile.createLink(cdkProjectJarLocation, IResource.HIDDEN | IResource.REPLACE, null);
View Full Code Here

   * @return a file designing the created package
   */
  public void run(IProgressMonitor monitor) {

    log.fine("Build jar");
    JarPackageData jarrer = new JarPackageData();

    jarrer.setExportJavaFiles(true);
    jarrer.setExportClassFiles(true);
    jarrer.setExportOutputFolders(true);
    jarrer.setOverwrite(true);

    try {
      // IJavaProject project =
      // (IJavaProject) resource.getProject().getNature(JavaCore.NATURE_ID);

      // check this is the case before letting this method get called
      Object element = resource.getAdapter(IJavaElement.class);
      IType type = ((ICompilationUnit) element).findPrimaryType();
      jarrer.setManifestMainClass(type);

      // Create a temporary JAR file name
      File baseDir = Activator.getDefault().getStateLocation().toFile();

      String prefix =
          String.format("%s_%s-", resource.getProject().getName(), resource
              .getName());
      File jarFile = File.createTempFile(prefix, ".jar", baseDir);
      jarrer.setJarLocation(new Path(jarFile.getAbsolutePath()));

      jarrer.setElements(resource.getProject().members(IResource.FILE));
      IJarExportRunnable runnable =
          jarrer.createJarExportRunnable(Display.getDefault()
              .getActiveShell());
      runnable.run(monitor);

      this.jarFile = jarFile;

View Full Code Here

TOP

Related Classes of org.eclipse.jdt.ui.jarpackager.JarPackageData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.