Пример #1
0
 public LogicalViewChildren(
     AntProjectHelper helper, PropertyEvaluator evaluator, Project project) {
   assert helper != null;
   this.helper = helper;
   projectDir = helper.getProjectDirectory();
   this.evaluator = evaluator;
   this.project = project;
 }
 private void btnDefinitionActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnDefinitionActionPerformed
   File f = FileUtil.toFile(helper.getProjectDirectory()); // NOI18N
   String curr = SharableLibrariesUtils.browseForLibraryLocation(getLibraryLocation(), this, f);
   if (curr != null) {
     setLibraryLocation(curr);
   }
 } // GEN-LAST:event_btnDefinitionActionPerformed
  @Messages({
    "WARN_MakeSharable.absolutePath=<html>Please make sure that the absolute path in the Libraries Folder field is valid for all users.<html>",
    "WARN_makeSharable.relativePath=<html>Please make sure that the relative path in the Libraries Folder field is valid for all users.<html>"
  })
  boolean isValidPanel() {
    String location = getLibraryLocation();
    boolean wrong = false;
    if (new File(location).isAbsolute()) {
      settings.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, WARN_MakeSharable_absolutePath());
      wrong = true;
    } else {
      File projectLoc = FileUtil.toFile(helper.getProjectDirectory());
      File libLoc = PropertyUtils.resolveFile(projectLoc, location);
      if (!CollocationQuery.areCollocated(projectLoc, libLoc)) {
        settings.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, WARN_makeSharable_relativePath());
        wrong = true;
      }
    }
    if (!wrong) {
      settings.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, null);
    }

    return true;
  }
  public Set /*<FileObject>*/ instantiate() throws IOException {

    Set<FileObject> resultSet = new LinkedHashSet<FileObject>();
    File dirPr = (File) wiz.getProperty("projdir"); // NOI18N
    if (dirPr != null) {
      dirPr = FileUtil.normalizeFile(dirPr);
    }

    String name = (String) wiz.getProperty("name"); // NOI18N

    final String activePlatform = (String) wiz.getProperty("activePlatform"); // NOI18N
    final String activeDevice = (String) wiz.getProperty("activeDevice"); // NOI18N
    final String activeProfile = (String) wiz.getProperty("activeProfile"); // NOI18N
    Properties props = (Properties) wiz.getProperty("additionalProperties"); // NOI18N
    final FileObject template = Templates.getTemplate(wiz);
    PlatformSelectionPanel.PlatformDescription pd =
        (PlatformSelectionPanel.PlatformDescription)
            wiz.getProperty(PlatformSelectionPanel.PLATFORM_DESCRIPTION);
    AntProjectHelper h =
        J2MEProjectGenerator.createProject(
            dirPr,
            name,
            pd,
            new J2MEProjectGenerator.ProjectGeneratorCallback() {
              public void doPostGeneration(
                  Project p,
                  final AntProjectHelper h,
                  FileObject dir,
                  File projectLocationFile,
                  ArrayList<String> configurations)
                  throws IOException {

                createManifest(dir, MANIFEST_FILE);
                unZipFile(template.getInputStream(), dir);

                final FileObject lib = dir.getFileObject("lib");
                if (lib != null) {
                  final ReferenceHelper refHelper =
                      (ReferenceHelper) p.getLookup().lookup(ReferenceHelper.class);
                  try {
                    ProjectManager.mutex()
                        .writeAccess(
                            new Mutex.ExceptionAction() {
                              public Object run() throws Exception {
                                final List<String> entries = new ArrayList<String>();
                                final FileObject[] libs = lib.getChildren();
                                for (int i = 0; i < libs.length; i++) {
                                  String ref =
                                      refHelper.createForeignFileReference(
                                          FileUtil.normalizeFile(FileUtil.toFile(libs[i])), null);
                                  entries.add(ref + ((i < libs.length - 1) ? ";" : ""));
                                }

                                EditableProperties editableProps =
                                    h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
                                editableProps.setProperty(
                                    "extra.classpath", entries.toArray(new String[entries.size()]));
                                editableProps.setProperty(
                                    "libs.classpath", entries.toArray(new String[entries.size()]));
                                h.putProperties(
                                    AntProjectHelper.PROJECT_PROPERTIES_PATH,
                                    editableProps); // #47609
                                return null;
                              }
                            });
                  } catch (MutexException me) {
                    ErrorManager.getDefault().notify(me);
                  }
                }

                final FileObject res = dir.getFileObject("resources");
                if (res != null) {
                  final ReferenceHelper refHelper =
                      (ReferenceHelper) p.getLookup().lookup(ReferenceHelper.class);
                  try {
                    ProjectManager.mutex()
                        .writeAccess(
                            new Mutex.ExceptionAction() {
                              public Object run() throws Exception {
                                String ref =
                                    ";"
                                        + refHelper.createForeignFileReference(
                                            FileUtil.normalizeFile(FileUtil.toFile(res)), null);

                                EditableProperties editableProps =
                                    h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
                                editableProps.setProperty(
                                    "libs.classpath",
                                    editableProps.getProperty("libs.classpath") + ref);
                                h.putProperties(
                                    AntProjectHelper.PROJECT_PROPERTIES_PATH,
                                    editableProps); // #47609
                                return null;
                              }
                            });
                  } catch (MutexException me) {
                    ErrorManager.getDefault().notify(me);
                  }
                }

                Properties parsed = parseRicohAdditionalResources(dir);
                if (parsed != null) {
                  Iterator entries = parsed.entrySet().iterator();
                  while (entries.hasNext()) {
                    final Map.Entry elem = (Map.Entry) entries.next();
                    final Object value = elem.getValue();
                    if (value instanceof File) {
                      final ReferenceHelper refHelper =
                          (ReferenceHelper) p.getLookup().lookup(ReferenceHelper.class);
                      if (value != null && ((File) value).exists()) {
                        try {
                          ProjectManager.mutex()
                              .writeAccess(
                                  new Mutex.ExceptionAction() {
                                    public Object run() throws Exception {
                                      String ref =
                                          refHelper.createForeignFileReference(
                                              FileUtil.normalizeFile((File) value), null);
                                      EditableProperties props =
                                          h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
                                      props.put((String) elem.getKey(), ref);
                                      h.putProperties(
                                          AntProjectHelper.PROJECT_PROPERTIES_PATH,
                                          props); // #47609
                                      return null;
                                    }
                                  });
                        } catch (MutexException me) {
                          ErrorManager.getDefault().notify(me);
                        }
                      }
                    } else {
                      EditableProperties editableProps =
                          h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
                      editableProps.setProperty(
                          (String) elem.getKey(), String.valueOf(elem.getValue()));
                      h.putProperties(
                          AntProjectHelper.PROJECT_PROPERTIES_PATH, editableProps); // #47609
                    }
                  }
                }

                JavaPlatform[] platforms =
                    JavaPlatformManager.getDefault()
                        .getPlatforms(
                            activePlatform,
                            new Specification(CDCPlatform.PLATFORM_CDC, null)); // NOI18N
                if (platforms.length != 0) {
                  CDCPlatform cdcplatform = (CDCPlatform) platforms[0];
                  final EditableProperties ep =
                      h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
                  ep.setProperty(
                      CDCPropertiesDescriptor.APPLICATION_NAME,
                      p.getProjectDirectory().getNameExt());
                  ep.setProperty(
                      DefaultPropertiesDescriptor.PLATFORM_ACTIVE,
                      cdcplatform.getAntName()); // NOI18N
                  ep.setProperty(
                      DefaultPropertiesDescriptor.PLATFORM_ACTIVE_DESCRIPTION,
                      cdcplatform.getDisplayName()); // NOI18N
                  ep.setProperty(DefaultPropertiesDescriptor.PLATFORM_TRIGGER, "CDC"); // NOI18N
                  ep.setProperty(
                      DefaultPropertiesDescriptor.PLATFORM_TYPE, cdcplatform.getType()); // NOI18N
                  String classVersion = cdcplatform.getClassVersion();
                  ep.setProperty(
                      DefaultPropertiesDescriptor.PLATFORM_DEVICE, activeDevice); // NOI18N
                  ep.setProperty(
                      DefaultPropertiesDescriptor.PLATFORM_PROFILE, activeProfile); // NOI18N
                  // add bootclasspath
                  NewCDCProjectWizardIterator.generatePlatformProperties(
                      cdcplatform, activeDevice, activeProfile, ep); // NOI18N
                  ep.setProperty(
                      DefaultPropertiesDescriptor.JAVAC_SOURCE,
                      classVersion != null ? classVersion : "1.2"); // NOI18N
                  ep.setProperty(
                      DefaultPropertiesDescriptor.JAVAC_TARGET,
                      classVersion != null ? classVersion : "1.2"); // NOI18N
                  h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
                } else {
                  throw new IllegalArgumentException("No CDC platform installed"); // NOI18N
                }
              }
            });

    resultSet.add(h.getProjectDirectory());
    dirPr = (dirPr != null) ? dirPr.getParentFile() : null;
    if (dirPr != null && dirPr.exists()) {
      ProjectChooser.setProjectsFolder(dirPr);
    }
    return resultSet;
  }