Java Code Examples for org.openide.util.Exceptions#printStackTrace()

The following examples show how to use org.openide.util.Exceptions#printStackTrace() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: netbeans   File: Detector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Thread.sleep(INITIAL_PAUSE);
        while (isRunning()) {
            long time = System.currentTimeMillis();
            detectDeadlock();
            if (LOG.isLoggable(Level.FINE)) {
                LOG.log(Level.FINE, "Deadlock detection took: {0} ms.", System.currentTimeMillis() - time); // NOI18N
            }
            if (isRunning()) {
                Thread.sleep(PAUSE);
            }
        }
    } catch (InterruptedException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example 2
/**
 * Compute lenght of this sequence - quite expensive operation, indeed.
 */
@Override
public synchronized int length() {
    if (length == -1) {
        try {
            if (charBufferStartsAt == -1) {
                reset();
            }
            while (shiftBuffer()) {
                if (terminated) {
                    throw new TerminatedException();

                }
                // call to decode the whole file
            }
            length = charBufferStartsAt + charBuffer.limit();
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    return length;
}
 
Example 3
Source Project: netbeans   File: PackageRootNode.java    License: Apache License 2.0 6 votes vote down vote up
private PackageRootNode( SourceGroup group, Children ch) {
    super(ch, new ProxyLookup(createLookup(group), Lookups.singleton(
            SearchInfoDefinitionFactory.createSearchInfoBySubnodes(ch))));
    this.group = group;
    file = group.getRootFolder();
    files = Collections.singleton(file);
    try {
        FileSystem fs = file.getFileSystem();
        fileSystemListener = FileUtil.weakFileStatusListener(this, fs);
        fs.addFileStatusListener(fileSystemListener);
    } catch (FileStateInvalidException e) {            
        Exceptions.printStackTrace(Exceptions.attachMessage(e,"Can not get " + file + " filesystem, ignoring...")); //NOI18N
    }
    setName( group.getName() );
    setDisplayName( group.getDisplayName() );        
    // setIconBase("org/netbeans/modules/java/j2seproject/ui/resources/packageRoot");
}
 
Example 4
Source Project: netbeans   File: JavaSource.java    License: Apache License 2.0 6 votes vote down vote up
private static @NullUnknown JavaSource _create(final ClasspathInfo cpInfo, final @NonNull Collection<? extends FileObject> files) throws IllegalArgumentException {
        if (files == null) {
            throw new IllegalArgumentException ();
        }
        if (!NoJavacHelper.hasWorkingJavac())
            return null;
        try {
            return new JavaSource(cpInfo, files);
// TODO: Split
//        } catch (DataObjectNotFoundException donf) {
//            Logger.getLogger("global").warning("Ignoring non existent file: " + FileUtil.getFileDisplayName(donf.getFileObject()));     //NOI18N
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
        return null;
    }
 
Example 5
Source Project: netbeans   File: EclipseUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void tryLoad(Properties p, File f) {
    if (!f.isFile()) {
        return;
    }
    try {
        InputStream is = new FileInputStream(f);
        try {
            p.load(is);
        } finally {
            is.close();
        }
    } catch (IOException x) {
        Exceptions.printStackTrace(x);
    }
}
 
Example 6
Source Project: netbeans   File: SetExecutionUriAction.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean isServletFile(WebModule webModule, FileObject javaClass,
        boolean initialScan) 
{
    if (webModule == null ) {
        return false;
    }
    
    ClassPath classPath = ClassPath.getClassPath (javaClass, ClassPath.SOURCE);
    if (classPath == null) {
        return false;
    }
    String className = classPath.getResourceName(javaClass,'.',false);
    if (className == null) {
        return false;
    }
    
    try {
        MetadataModel<WebAppMetadata> metadataModel = webModule
                .getMetadataModel();
        boolean result = false;
        if ( initialScan || metadataModel.isReady()) {
            List<ServletInfo> servlets = WebAppMetadataHelper
                    .getServlets(metadataModel);
            List<String> servletClasses = new ArrayList<String>( servlets.size() );
            for (ServletInfo si : servlets) {
                if (className.equals(si.getServletClass())) {
                    result =  true;
                }
                else {
                    servletClasses.add( si.getServletClass() );
                }
            }
            setServletClasses( servletClasses,  javaClass , initialScan);
        }
        return result;
    } catch (java.io.IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    return false;
}
 
Example 7
Source Project: netbeans   File: VanillaCompileWorker.java    License: Apache License 2.0 5 votes vote down vote up
private static void fallbackCopyExistingClassFiles(final Context context,
                                               final JavaParsingContext javaContext,
                                               final Collection<? extends CompileTuple> files) {
//fallback: copy output classes to caches, so that editing is not extremely slow/broken:
BinaryForSourceQuery.Result res2 = BinaryForSourceQuery.findBinaryRoots(context.getRootURI());
Set<String> filter;
if (!context.isAllFilesIndexing()) {
    filter = new HashSet<>();
    for (CompileTuple toIndex : files) {
        String path = toIndex.indexable.getRelativePath();
        filter.add(path.substring(0, path.lastIndexOf(".")));
    }
} else {
    filter = null;
}
try {
    final Future<Void> done = FileManagerTransaction.runConcurrent(() -> {
        File cache = JavaIndex.getClassFolder(context.getRootURI(), false, false);
        for (URL u : res2.getRoots()) {
            FileObject binaryFO = URLMapper.findFileObject(u);
            if (binaryFO == null)
                continue;
            FileManagerTransaction fmtx = TransactionContext.get().get(FileManagerTransaction.class);
            List<File> copied = new ArrayList<>();
            copyRecursively(binaryFO, cache, cache, filter, fmtx, copied);
            final ClassIndexImpl cii = javaContext.getClassIndexImpl();
            if (cii != null) {
                cii.getBinaryAnalyser().analyse(context, cache, copied);
            }
        }
    });
    done.get();
} catch (IOException | InterruptedException | ExecutionException ex) {
    Exceptions.printStackTrace(ex);
}
}
 
Example 8
Source Project: netbeans   File: PhpUnitOptionsPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void skelGenLearnMoreLabelMousePressed(MouseEvent evt) {//GEN-FIRST:event_skelGenLearnMoreLabelMousePressed
    try {
        URL url = new URL("https://github.com/sebastianbergmann/phpunit-skeleton-generator"); // NOI18N
        HtmlBrowser.URLDisplayer.getDefault().showURL(url);
    } catch (MalformedURLException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example 9
public String createConfiguration(String configurationType, String configurationName) {
    EditableProperties props = new EditableProperties(true);
    props.put("type", configurationType); //NOI18N
    props.put("display.name", configurationName); //NOI18N
    FileObject conf;
    try {
        conf = ConfigUtils.createConfigFile(p.getProjectDirectory(), configurationType, props);
        MobileConfigurationImpl cfg = MobileConfigurationImpl.create(p, conf);
        return cfg.getId();
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    return null;
}
 
Example 10
Source Project: netbeans   File: WebProjectFactory.java    License: Apache License 2.0 5 votes vote down vote up
public String calculateKey(ProjectImportModel model) {
    WebContentData webData;
    try {
        webData = parseWebContent(model.getEclipseProjectFolder());
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
        webData = new WebContentData();
        webData.contextRoot = "??"; //NOI18N
        webData.webRoot = "??"; //NOI18N
    }
    return ProjectFactorySupport.calculateKey(model) + "web=" + webData.webRoot + ";" + "context=" + webData.contextRoot + ";"; //NOI18N
}
 
Example 11
Source Project: netbeans   File: EntRefContainerImpl.java    License: Apache License 2.0 5 votes vote down vote up
public ResourceRef createResourceRef() throws IOException {
    try {
        return (ResourceRef) getWebApp().createBean("ResourceRef");//NOI18N
    } catch (ClassNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    }
    return null;
}
 
Example 12
Source Project: netbeans   File: Hacks.java    License: Apache License 2.0 5 votes vote down vote up
public static Scope constructScope(CompilationInfo info, String... importedClasses) {
    StringBuilder clazz = new StringBuilder();

    clazz.append("package $$;\n");

    for (String i : importedClasses) {
        clazz.append("import ").append(i).append(";\n");
    }

    clazz.append("public class $$scopeclass$").append(inc++).append("{");

    clazz.append("private void test() {\n");
    clazz.append("}\n");
    clazz.append("}\n");

    JavacTaskImpl jti = JavaSourceAccessor.getINSTANCE().getJavacTask(info);
    Context context = jti.getContext();

    JavaCompiler jc = JavaCompiler.instance(context);
    Log.instance(context).nerrors = 0;

    JavaFileObject jfo = FileObjects.memoryFileObject("$$", "$", new File("/tmp/t.java").toURI(), System.currentTimeMillis(), clazz.toString());

    try {
        CompilationUnitTree cut = ParserFactory.instance(context).newParser(jfo.getCharContent(true), true, true, true).parseCompilationUnit();

        jti.analyze(jti.enter(Collections.singletonList(cut)));

        return new ScannerImpl().scan(cut, info);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
        return null;
    } finally {
    }
}
 
Example 13
Source Project: netbeans   File: HTMLDialogImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void initPage() {
    try {
        onPageLoad.run();
    } catch (Throwable t) {
        Exceptions.printStackTrace(t);
    }
    final JButton[] buttons = Buttons.buttons();
    dd.setOptions(buttons);
}
 
Example 14
Source Project: netbeans   File: SourcePathProviderImpl.java    License: Apache License 2.0 5 votes vote down vote up
private static Map<String, Integer> getSourceRootsOrder(File baseDir) {
    try {
        String root = BaseUtilities.toURI(baseDir).toURL().toExternalForm();
        return getSourceRootsOrder(root);
    } catch (MalformedURLException ex) {
        Exceptions.printStackTrace(ex);
        return null;
    }
}
 
Example 15
Source Project: netbeans   File: RunAsRemoteWeb.java    License: Apache License 2.0 5 votes vote down vote up
private void indexFileBrowseButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_indexFileBrowseButtonActionPerformed
    try {
        Utils.browseFolderFile(PhpVisibilityQuery.getDefault(), sourcesFolderProvider.getSourcesFolder(), indexFileTextField);
    } catch (FileNotFoundException ex) {
        // cannot happen for sources
        Exceptions.printStackTrace(ex);
    }
}
 
Example 16
Source Project: netbeans   File: AntBuildExtender.java    License: Apache License 2.0 5 votes vote down vote up
private String assertMessage(FileObject extensionXml) {
    try {
        return "Extension file:" + extensionXml.asText() + " is owned by " + FileOwnerQuery.getOwner(extensionXml) +
                " but should be " + implementation.getOwningProject();
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
        return ex.getMessage();
    }
}
 
Example 17
Source Project: netbeans   File: EarImpl.java    License: Apache License 2.0 5 votes vote down vote up
/** META-INF folder for the Ear.
 */
@Override
public FileObject getMetaInf() {
    String appsrcloc =  PluginPropertyUtils.getPluginProperty(project, Constants.GROUP_APACHE_PLUGINS,
            Constants.PLUGIN_EAR, "earSourceDirectory", "ear", null);//NOI18N
    if (appsrcloc == null) {
        appsrcloc = "src/main/application";//NOI18N
    }
    URI dir = FileUtilities.getDirURI(project.getProjectDirectory(), appsrcloc);
    FileObject root = FileUtilities.convertURItoFileObject(dir);
    if (root == null) {
        final File fil = new File(dir);
        final boolean rootCreated = fil.mkdirs();
        if (rootCreated) {
            project.getProjectDirectory().refresh();
            root = FileUtil.toFileObject(fil);
        }
    }
    if (root != null) {
        FileObject metainf = root.getFileObject("META-INF");//NOI18N
        if (metainf == null) {
            try {
                metainf = root.createFolder("META-INF");
            } catch (IOException iOException) {
                Exceptions.printStackTrace(iOException);
            }
        }
        return metainf;
    }
    return null;
}
 
Example 18
Source Project: netbeans   File: ClassPathProviderImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
        @NonNull
        public List<? extends PathResourceImplementation> getResources() {
            List<PathResourceImplementation> res = cache.get();
            if (res != null) {
                return res;
            }
            final String propVal = eval.getProperty(filteredProp);
            final File propFile = propVal == null ? null : helper.resolveFile(propVal);
            URL propURL = null;
            try {
                if (propFile != null) {
                    propURL = Utilities.toURI(propFile).toURL();
                }
            } catch (MalformedURLException e) {
                Exceptions.printStackTrace(e);
            }
            final List<? extends PathResourceImplementation> resources = delegate.getResources();
            res = new ArrayList<PathResourceImplementation>(resources.size());
next:       for (PathResourceImplementation pri : resources) {
                if (propURL != null) {
                    final URL[] roots = pri.getRoots();
                    for (URL root : roots) {
                        if (propURL.equals(root) && roots.length == 1) {
                            continue next;
                        }
                    }
                }
                res.add(pri);
            }
            res = Collections.unmodifiableList(res);
            if (!cache.compareAndSet(null, res)) {
                final List<PathResourceImplementation> cur = cache.get();
                if (cur != null) {
                    res = cur;
                }
            }
            return res;
        }
 
Example 19
Source Project: netbeans   File: ChromeBrowserImpl.java    License: Apache License 2.0 5 votes vote down vote up
/** Call setURL again to force reloading.
 * Browser must be set to reload document and do not cache them.
 */
@Override
public void reloadDocument() {
    if (url == null) {
        return;
    }
    BrowserTabDescriptor tab = getBrowserTabDescriptor();
    if (tab != null) {
        URL u = url;
        // if user navigated to a different URL then reload the new URL
        // for example going from .../index.html to .../index.html#page2
        // must reload .../index.html#page2
        if (newURL != null) {
            try {
                URL u2 = new URL(newURL);
                // use new URL only if the hostname and port are the same
                if (u2.getAuthority() != null && u2.getAuthority().equals(u.getAuthority())) {
                    u = u2;
                }
            } catch (MalformedURLException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
        ExternalBrowserPlugin.getInstance().showURLInTab(tab, u);
    } else if (!hasEnhancedMode()) {
        setURL(url);
    }
}
 
Example 20
Source Project: netbeans   File: EjbJarProject.java    License: Apache License 2.0 4 votes vote down vote up
private void updateProject() {
    // Make it easier to run headless builds on the same machine at least.
    EditableProperties ep = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH);
    ep.setProperty("netbeans.user", System.getProperty("netbeans.user"));
    
    //remove jaxws.endorsed.dir property
    ep.remove("jaxws.endorsed.dir");

    // #134642 - use Ant task from copylibs library
    SharabilityUtility.makeSureProjectHasCopyLibsLibrary(helper, refHelper);
    
    //update lib references in project properties
    EditableProperties props = updateHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
    if (props.getProperty(EjbJarProjectProperties.J2EE_DEPLOY_ON_SAVE) == null) {
        String server = evaluator().getProperty(EjbJarProjectProperties.J2EE_SERVER_INSTANCE);
        props.setProperty(EjbJarProjectProperties.J2EE_DEPLOY_ON_SAVE, 
            server == null ? "false" : DeployOnSaveUtils.isDeployOnSaveSupported(server));
    }
    
    if (props.getProperty(EjbJarProjectProperties.J2EE_COMPILE_ON_SAVE) == null) {
        props.setProperty(EjbJarProjectProperties.J2EE_COMPILE_ON_SAVE, 
                props.getProperty(EjbJarProjectProperties.J2EE_DEPLOY_ON_SAVE));
    }
    J2EEProjectProperties.removeObsoleteLibraryLocations(ep);
    J2EEProjectProperties.removeObsoleteLibraryLocations(props);
    
    if (!props.containsKey(ProjectProperties.INCLUDES)) {
        props.setProperty(ProjectProperties.INCLUDES, "**"); // NOI18N
    }
    if (!props.containsKey(ProjectProperties.EXCLUDES)) {
        props.setProperty(ProjectProperties.EXCLUDES, ""); // NOI18N
    }
    if (!props.containsKey("build.generated.sources.dir")) { // NOI18N
        props.setProperty("build.generated.sources.dir", "${build.dir}/generated-sources"); // NOI18N
    }
    
    if (!props.containsKey(ProjectProperties.ANNOTATION_PROCESSING_ENABLED))props.setProperty(ProjectProperties.ANNOTATION_PROCESSING_ENABLED, "true"); //NOI18N
    if (!props.containsKey(ProjectProperties.ANNOTATION_PROCESSING_ENABLED_IN_EDITOR))props.setProperty(ProjectProperties.ANNOTATION_PROCESSING_ENABLED_IN_EDITOR, "true"); //NOI18N
    if (!props.containsKey(ProjectProperties.ANNOTATION_PROCESSING_RUN_ALL_PROCESSORS))props.setProperty(ProjectProperties.ANNOTATION_PROCESSING_RUN_ALL_PROCESSORS, "true"); //NOI18N
    if (!props.containsKey(ProjectProperties.ANNOTATION_PROCESSING_PROCESSORS_LIST))props.setProperty(ProjectProperties.ANNOTATION_PROCESSING_PROCESSORS_LIST, ""); //NOI18N
    if (!props.containsKey(ProjectProperties.ANNOTATION_PROCESSING_SOURCE_OUTPUT))props.setProperty(ProjectProperties.ANNOTATION_PROCESSING_SOURCE_OUTPUT, "${build.generated.sources.dir}/ap-source-output"); //NOI18N
    if (!props.containsKey(ProjectProperties.JAVAC_PROCESSORPATH))props.setProperty(ProjectProperties.JAVAC_PROCESSORPATH,"${" + ProjectProperties.JAVAC_CLASSPATH + "}"); //NOI18N
    if (!props.containsKey("javac.test.processorpath"))props.setProperty("javac.test.processorpath", "${" + ProjectProperties.JAVAC_TEST_CLASSPATH + "}"); // NOI18N

    updateHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);            
    
    helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep);
    // update a dual build directory project to use a single build directory
    ep = updateHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
    String earBuildDir = ep.getProperty(EjbJarProjectProperties.BUILD_EAR_CLASSES_DIR);
    if (null != earBuildDir) {
        // there is an BUILD_EAR_CLASSES_DIR property... we may 
        //  need to change its value
        String buildDir = ep.getProperty(ProjectProperties.BUILD_CLASSES_DIR);
        if (null != buildDir) {
            // there is a value that we may need to change the 
            // BUILD_EAR_CLASSES_DIR property value to match.
            if (!buildDir.equals(earBuildDir)) {
                // the values do not match... update the property and save it
                ep.setProperty(EjbJarProjectProperties.BUILD_EAR_CLASSES_DIR,
                        buildDir);
                updateHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,
                        ep);
            }
            // else {
            //   the values match and we don't need to do anything
            // }
        }
        // else {
        //   the project doesn't have a BUILD_CLASSES_DIR property
        //   ** This is not an expected state, but if the project 
        //      properties evolve, this property may go away...
        // }
    }
    // else {
    //   there isn't a BUILD_EAR_CLASSES_DIR in this project...
    //     so we should not create one, by setting it.
    // }

    try {
        ProjectManager.getDefault().saveProject(EjbJarProject.this);
    } catch (IOException e) {
        Exceptions.printStackTrace(e);
    }
}