private void createCatalogIfRequired(RetrieveEntry rent) {
   URI curURI = null;
   String addr = rent.getEffectiveAddress();
   try {
     // check if this is the first entry and the connection was redirected. If yes, then
     // store the URI as the original URI instead of the redirected URI
     String tempStr =
         URLResourceRetriever.resolveURL(rent.getBaseAddress(), rent.getCurrentAddress());
     if (!(new URI(tempStr).equals(new URI(addr)))) {
       addr = tempStr;
     }
   } catch (URISyntaxException ex) {
     // ignore
   }
   if (isSave2SingleFolder()) {
     if (!rent.getCurrentAddress().equals(rent.getEffectiveAddress()))
       addr = rent.getCurrentAddress();
   }
   try {
     curURI = new URI(addr);
   } catch (URISyntaxException ex) {
     // this is not supposed to happen. But if it does, then just return
     return;
   }
   FileObject fobj = null;
   try {
     fobj = FileUtil.toFileObject(FileUtil.normalizeFile(rent.getSaveFile()));
   } catch (Exception e) {
     return;
   }
   if (fobj == null) return;
   CatalogWriteModel dr = null;
   try {
     if (this.catalogFileObject == null) {
       Project project = FileOwnerQuery.getOwner(fobj);
       if (project == null) {
         // See issue #176769
         // In can happen if the file was saved outside of the project
         return;
       }
       dr = CatalogWriteModelFactory.getInstance().getCatalogWriteModelForProject(fobj);
     } else {
       dr =
           CatalogWriteModelFactory.getInstance()
               .getCatalogWriteModelForCatalogFile(this.catalogFileObject);
     }
   } catch (CatalogModelException ex) {
     // ignore this exception but return
     return;
   }
   // fobj = FileUtil.toFileObject(rent.getSaveFile());
   try {
     dr.addURI(curURI, fobj);
   } catch (Exception ex) {
     // ignore this exception but return
     ex = new Exception("Exception while writing in to catalog.", ex);
     handleException(rent, ex);
     return;
   }
 }
Beispiel #2
0
  /**
   * Perform special enablement check in addition to the normal one.
   *
   * <p>protected boolean enable (Node[] nodes) { if (!super.enable(nodes)) { return false; } }
   *
   * <p>if (...) { ... }
   */
  @Override
  protected boolean enable(Node[] nodes) {
    if (nodes.length == 0) {
      return false;
    }

    for (Node node : nodes) {
      DataObject dataObj = node.getCookie(DataObject.class);
      if (dataObj != null) {
        FileObject fileObj = dataObj.getPrimaryFile();
        if ((fileObj == null) || !fileObj.isValid()) {
          continue;
        }

        Project prj = FileOwnerQuery.getOwner(fileObj);
        if ((prj == null) || (getSourceGroup(fileObj, prj) == null)) {
          continue;
        }

        if (TestUtil.isJavaFile(fileObj) || (node.getCookie(DataFolder.class) != null)) {
          return true;
        }
      }
    }
    return false;
  }
Beispiel #3
0
 public Project getProject() {
   Project prj = project.get();
   if (prj == null) {
     prj = FileOwnerQuery.getOwner(projectURI);
     project = new WeakReference<Project>(prj);
   }
   return prj;
 }
 private void initProjectInfo() {
   Project p = FileOwnerQuery.getOwner(fileObject);
   if (p != null) {
     ProjectInformation pi = ProjectUtils.getInformation(p);
     projectName = pi.getDisplayName();
     projectIcon = pi.getIcon();
   }
 }
 public final PlatypusProject getProject() {
   Project pr = FileOwnerQuery.getOwner(getPrimaryFile());
   if (pr instanceof PlatypusProject) {
     return (PlatypusProject) pr;
   } else {
     return null;
   }
 }
  public static Project GetProjectFromDocument(Document document) {
    try {
      FileObject fileObject =
          (FileObject) NbEditorUtilities.getDataObject(document).files().toArray()[0];
      return FileOwnerQuery.getOwner(fileObject);
    } catch (Exception ex) {

      return null;
    }
  }
 public Project getProjectOwner(
     Project parentProject, SonarQubeProjectConfiguration projectConfiguration)
     throws MvnModelInputException {
   FileObject projectDir =
       findProjectDir(parentProject, projectConfiguration, getShortProjectKey());
   if (projectDir != null) {
     return FileOwnerQuery.getOwner(projectDir);
   } else {
     return null;
   }
 }
  public void refresh() {

    Properties props = getWebAppsProperties();
    props.forEach(
        (k, v) -> {
          File f = new File((String) v);
          Project p = FileOwnerQuery.getOwner(FileUtil.toFileObject(f));
          WebModule wm = WebModule.getWebModule(p.getProjectDirectory());
          String cp = wm.getContextPath();
        });
  }
Beispiel #9
0
    protected Node[] createNodes(Object key) {
      Node n = null;
      if (key == KEY_SOURCE_DIR) {
        FileObject srcRoot =
            helper.resolveFileObject(evaluator.getProperty(IcanproProjectProperties.SRC_DIR));
        Project p = FileOwnerQuery.getOwner(srcRoot);
        Sources s = ProjectUtils.getSources(p);
        SourceGroup sgs[] =
            ProjectUtils.getSources(p).getSourceGroups(IcanproProject.SOURCES_TYPE_ICANPRO);
        for (int i = 0; i < sgs.length; i++) {
          if (sgs[i].contains(srcRoot)) {
            n = PackageView.createPackageView(sgs[i]);
            break;
          }
        }
        /*
                  } else if (key == KEY_DOC_BASE) {
                      n = new DocBaseNode (getFolder(IcanproProjectProperties.META_INF).getNodeDelegate());
                  } else if (key == KEY_EJBS) {
                      FileObject srcRoot = helper.resolveFileObject(evaluator.getProperty (IcanproProjectProperties.SRC_DIR));
                      Project project = FileOwnerQuery.getOwner (srcRoot);
                      DDProvider provider = DDProvider.getDefault();
                      EjbJarImplementation jp = (EjbJarImplementation) project.getLookup().lookup(EjbJarImplementation.class);
                      org.netbeans.modules.j2ee.dd.api.ejb.EjbJar ejbJar = null;
                      try {
                          ejbJar = provider.getDDRoot(jp.getDeploymentDescriptor());
                      } catch (IOException ioe) {
                          ErrorManager.getDefault().notify(ioe);
                      }
                      ClassPathProvider cpp = (ClassPathProvider)
                          project.getLookup().lookup(ClassPathProvider.class);
                      assert cpp != null;
                      ClassPath classPath = cpp.findClassPath(srcRoot, ClassPath.SOURCE);
                      n = new EjbContainerNode(ejbJar, classPath);
                      //Node nws =  new WebServicesNode(ejbJar, classPath);
                      return n == null ? new Node[0] : new Node[] {n};
                  } else if (key == WEBSERVICES_DIR){
        FileObject 	srcRoot = helper.resolveFileObject(evaluator.getProperty (IcanproProjectProperties.SRC_DIR));
                      WebServicesView webServicesView = WebServicesView.getWebServicesView(srcRoot);
                      if(webServicesView != null)
        {
        n = webServicesView.createWebServicesView(srcRoot);
                      }
           } else if (key == KEY_SETUP_DIR) {
                      try {
                          DataObject sdo = DataObject.find(getSetupFolder());
                          n = new ServerResourceNode(project); // sdo.getNodeDelegate());
                      } catch (org.openide.loaders.DataObjectNotFoundException dnfe) {}
                      */
      }

      return n == null ? new Node[0] : new Node[] {n};
    }
Beispiel #10
0
  public LayoutScene(LayoutViewElement mve, LayoutDataObject obj) {
    super();

    this.dataObject = obj;

    multiview = mve;
    this.projectPath =
        FileOwnerQuery.getOwner(obj.getPrimaryFile()).getProjectDirectory().getPath();
    this.lSystem = LayoutParser.parse(obj);
    //        addSaveAsCapable();

    LayoutDocument ld = lSystem.getDocument();
    ld.addPropertyChangeListener(new DocumentDPIChangeListener());

    // paper layer
    this.paperWidget = new PaperWidget(this, ld);
    // add paper biar bisa diedit2
    ic.add(ld);
    paperLayer.addChild(paperWidget);

    layerController = LayerFactory.createLayer(this, lSystem.getLayers());
    // init em listener
    ExplorerManager em = layerController.getExplorerManager();
    em.addPropertyChangeListener(new NodeSelectionListener());
    // main layer, where sublayout widgets will be added
    mainLayer = layerController.getRootWidget();
    addChild(mainLayer);

    // selection layer, directly above the main layer
    selectionLayer = new LayerWidget(this);
    selectionWrapperWidget = new SelectionWrapperWidget(this);
    selectionLayer.addChild(selectionWrapperWidget);
    addChild(selectionLayer);

    //        getPriorActions().addAction(new KeySwitchToolAction());
    // scene's actions, applied to all selected widgets
    // key move tool, always available
    getActions().addAction(KEY_MOVE_ACTION);
    // move tool
    createActions(FREE_MOVE_TOOL).addAction(MOVE_ACTION);
    createActions(ON_AXIS_MOVE_TOOL).addAction(ON_AXIS_MOVE_ACTION);
    setActiveTool(FREE_MOVE_TOOL);
    // rotate on outside of selectedwrapper border
    createActions(SelectionWrapperWidget.TRANSFORM_TOOL).addAction(ROTATE_ACTION);
    // mirror selected layer, only on transform mode
    createActions(SelectionWrapperWidget.TRANSFORM_TOOL).addAction(MIRROR_ACTION);
    // show popup under right click to show layers under cursor
    getActions().addAction(SELECT_ACTION);
    getPriorActions().addAction(SCROLL_MODIFIER_ACTION);
    initLookup();

    createView();
  }
 public ClassPath findClassPath(FileObject file, String type) {
   Project p = FileOwnerQuery.getOwner(file);
   if (p != null) {
     ClassPathProvider cpp = p.getLookup().lookup(ClassPathProvider.class);
     if (cpp != null) {
       return cpp.findClassPath(file, type);
     } else {
       return null;
     }
   } else {
     return null;
   }
 }
 @Override
 public boolean appliesTo(RuleContext context) {
   HtmlParserResult result = (HtmlParserResult) context.parserResult;
   FileObject file = result.getSnapshot().getSource().getFileObject();
   if (file == null) {
     return false;
   }
   Project project = FileOwnerQuery.getOwner(file);
   if (project == null) {
     return false;
   }
   return true;
 }
 private URL[] find(FileObject file, SourceRoots from, SourceRoots to) {
   Project p = FileOwnerQuery.getOwner(file);
   if (p == null) {
     return null;
   }
   FileObject[] fromRoots = from.getRoots();
   for (int i = 0; i < fromRoots.length; i++) {
     if (fromRoots[i].equals(file)) {
       return to.getRootURLs();
     }
   }
   return null;
 }
  protected boolean enable(Node[] node) {
    if (node == null || node.length < 1) {
      return false;
    }
    DataObject dataObject = node[0].getCookie(DataObject.class);

    if (dataObject != null) {
      Project p = FileOwnerQuery.getOwner(dataObject.getPrimaryFile());
      if (p != null && GWTProjectInfo.isGWTProject(p)) {
        return ServiceRefactoringActionsProvider.canRename(getLookup(node));
      }
    }

    return false;
  }
  public List<FileObject> getWebAppFileObjects() {
    List<FileObject> list = new ArrayList<>();
    Properties props = getWebAppsProperties();
    props.forEach(
        (k, v) -> {
          FileObject fo = FileUtil.toFileObject(new File((String) v));
          if (fo != null) {
            Project p = FileOwnerQuery.getOwner(fo);
            if (p != null) {
              list.add(fo);
            }
          }
        });

    return list;
  }
Beispiel #16
0
  @Override
  public Action[] getActions(boolean arg0) {
    Action[] actions = super.getActions(arg0);

    final DataObject obj = getLookup().lookup(DataObject.class);
    final Project proj = FileOwnerQuery.getOwner(obj.getPrimaryFile());

    if (proj != null && proj instanceof GISProject) {
      Action[] temp = actions;
      actions = new Action[actions.length + 1];
      actions[0] = new NewMapContext((GISProject) proj);
      for (int i = 0; i < temp.length; i++) {
        actions[i + 1] = temp[i];
      }
    }

    return actions;
  }
Beispiel #17
0
 private String getProjectType() {
   String ret = "";
   TopComponent.Registry registry = TopComponent.getRegistry();
   TopComponent tc = registry.getActivated();
   if (tc != null) {
     Lookup lkup = tc.getLookup();
     if (lkup != null) {
       DataObject dObj = lkup.lookup(DataObject.class);
       if (dObj != null) {
         FileObject fObj = dObj.getPrimaryFile();
         Project project = FileOwnerQuery.getOwner(fObj);
         if (project != null) {
           ret = project.getClass().getName();
         }
       }
     }
   }
   return ret;
 }
 public boolean interestedInScript(File script, AntSession session) {
   FileObject projfile = FileUtil.toFileObject(FileUtil.normalizeFile(script));
   if (projfile == null) return false;
   Project proj = FileOwnerQuery.getOwner(projfile);
   if (proj == null) return false;
   AntProjectHelper helper = proj.getLookup().lookup(AntProjectHelper.class);
   if (helper == null) return false;
   String sourceRoot = helper.getStandardPropertyEvaluator().getProperty("src.dir"); // NOI18N
   if (sourceRoot == null) return false;
   File srcRoot = helper.resolveFile(sourceRoot);
   if (srcRoot == null) return false;
   HashMap<File, String> roots = (HashMap) session.getCustomData(this);
   if (roots == null) {
     roots = new HashMap();
     session.putCustomData(this, roots);
   }
   roots.put(
       script, srcRoot.getAbsolutePath().replaceAll(CHARSTOESCAPE, ESCAPESEQUENCE) + separator);
   return true;
 }
  ImmutableLayoutScene(DataObject obj, LayoutLSystem lSystem) {
    super();
    this.projectPath =
        FileOwnerQuery.getOwner(obj.getPrimaryFile()).getProjectDirectory().getPath();
    LayoutLSystem lSclone = new LayoutLSystem(lSystem);
    LayoutDocument ld = lSclone.getDocument();

    // paper layer
    this.paperWidget = new PaperWidget(this, ld);
    paperWidget.drawShadow = false;
    paperLayer.addChild(paperWidget);

    LayerController layerController = LayerFactory.createLayer(this, lSclone.getLayers());
    // main layer, where sublayout widgets will be added
    addChild(layerController.getRootWidget());

    for (Object o : getObjects()) {
      Widget w = findWidget(o);
      if (w instanceof SubLayoutWidget) {
        SubLayoutWidget slw = (SubLayoutWidget) w;
        slw.showEmptySquares(false);
      }
    }
  }
  public void testForeignClassBundler() throws Exception { // #155091 and deps
    TestFileUtils.writeFile(
        d,
        "a/pom.xml",
        "<project xmlns='http://maven.apache.org/POM/4.0.0'>"
            + "<modelVersion>4.0.0</modelVersion>"
            + "<groupId>grp</groupId>"
            + "<artifactId>art</artifactId>"
            + "<packaging>jar</packaging>"
            + "<version>0</version>"
            + "</project>");
    FileObject src = FileUtil.createFolder(d, "a/src/main/java");

    File repo = EmbedderFactory.getProjectEmbedder().getLocalRepositoryFile();
    File art =
        new File(
            repo,
            "grp" + File.separator + "art" + File.separator + "0" + File.separator + "art-0.jar");
    URL root = FileUtil.getArchiveRoot(Utilities.toURI(art).toURL());
    Project p = ProjectManager.getDefault().findProject(d.getFileObject("a"));
    FileOwnerQuery.markExternalOwner(
        Utilities.toURI(art), p, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
    MavenFileOwnerQueryImpl.getInstance()
        .registerCoordinates("grp", "art", "0", d.getFileObject("a").toURL());

    SourceForBinaryQuery.Result2 r = SourceForBinaryQuery.findSourceRoots2(root);
    assertEquals(Collections.singletonList(src), Arrays.asList(r.getRoots()));
    assertTrue(r.preferSources());
    TestFileUtils.writeFile(
        d,
        "b/pom.xml",
        "<project xmlns='http://maven.apache.org/POM/4.0.0'>"
            + "<modelVersion>4.0.0</modelVersion>"
            + "<groupId>grp</groupId>"
            + "<artifactId>art</artifactId>"
            + "<packaging>war</packaging>"
            + "<version>0</version>"
            + "</project>");
    src = FileUtil.createFolder(d, "b/src/main/java");

    art =
        new File(
            repo,
            "grp" + File.separator + "art" + File.separator + "0" + File.separator + "art-0.jar");
    FileOwnerQuery.markExternalOwner(
        Utilities.toURI(art),
        ProjectManager.getDefault().findProject(d.getFileObject("b")),
        FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
    root = FileUtil.getArchiveRoot(Utilities.toURI(art).toURL());
    p = ProjectManager.getDefault().findProject(d.getFileObject("b"));
    FileOwnerQuery.markExternalOwner(
        Utilities.toURI(art), p, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
    MavenFileOwnerQueryImpl.getInstance()
        .registerCoordinates("grp", "art", "0", d.getFileObject("b").toURL());

    r = SourceForBinaryQuery.findSourceRoots2(root);
    assertEquals(Collections.singletonList(src), Arrays.asList(r.getRoots()));
    assertFalse(r.preferSources());

    // 215242 assert that output dir does prefer sources
    r = SourceForBinaryQuery.findSourceRoots2(new URL(d.toURL(), "b/target/classes/"));
    assertEquals(Collections.singletonList(src), Arrays.asList(r.getRoots()));
    assertTrue(r.preferSources());
  }
Beispiel #21
0
 /**
  * Determines parent project for a file.
  *
  * @param file file to examine
  * @return Project owner of the file or null if the file does not belong to a project
  */
 public static Project getProject(File file) {
   if (file == null) return null;
   FileObject fo = FileUtil.toFileObject(file);
   if (fo == null) return getProject(file.getParentFile());
   return FileOwnerQuery.getOwner(fo);
 }
    @Override
    public URL[] getRoots() {
      ResolvedDependencies rd = rd();
      if (rd == null) { // corrupt project metadata
        return new URL[0];
      }
      ResolvedDependency d = rd.get(dep.getID());
      if (d == null) {
        // temporary workaround for mis-created project deps
        Logger.getLogger(DependenciesClasspathImpl.class.getName())
            .log(Level.WARNING, "Unresolvable dependency {0} in {1}", new Object[] {dep, get()});
        return new URL[0];
      }
      assert d != null : "Dependency " + dep + " resolves to null";

      List<URL> urls = new ArrayList<URL>();
      File f = d.resolveFile(ArtifactKind.ORIGIN);
      if (f != null) {
        if (d.getKind().isProjectDependency()) {
          FileObject fo = FileUtil.toFileObject(f);
          if (fo != null) {
            Project p = FileOwnerQuery.getOwner(fo);
            if (p != null) {
              try {
                URL url = p.getProjectDirectory().getURL();
                AntArtifactProvider prov = p.getLookup().lookup(AntArtifactProvider.class);
                for (AntArtifact a : prov.getBuildArtifacts()) {
                  if (JavaProjectConstants.ARTIFACT_TYPE_JAR.equals(a.getType())) {
                    URI[] uris = a.getArtifactLocations();
                    for (URI u : uris) {
                      url = new URL(u.toString());
                      if (FileUtil.isArchiveFile(url)) {
                        url = FileUtil.getArchiveRoot(url);
                        urls.add(url);
                      }
                    }
                  }
                }
              } catch (MalformedURLException ex) {
                Exceptions.printStackTrace(ex);
              } catch (FileStateInvalidException ex) {
                Exceptions.printStackTrace(ex);
              }
            }
          }
        } else {
          if (f != null) {
            try {
              URL url = f.toURI().toURL();
              if (FileUtil.isArchiveFile(url)) {
                url = FileUtil.getArchiveRoot(url);
              }
              urls.add(url);
            } catch (MalformedURLException ex) {
              Exceptions.printStackTrace(ex);
            }
          }
        }
      }
      return urls.toArray(new URL[urls.size()]);
    }