use of org.netbeans.api.annotations.common.CheckForNull in project python4nb by ebresie.
the class FileUtils method decompressTarGz.
// TODO: Determine if really need to "Download Python Source" like is done with Node js
// public static boolean downloadNodeSources(Version version, boolean iojs) throws NetworkException, IOException {
// assert !EventQueue.isDispatchThread();
// assert version != null;
// deleteExistingNodeSources(version);
// File nodeSources = PythonUtils.getNodeSources();
// String nodeVersion = version.toString();
// File archive = new File(nodeSources, (iojs ? "iojs" : "nodejs") + "-" + nodeVersion + ".tar.gz"); // NOI18N
// if (!downloadNodeSources(archive, nodeVersion, iojs)) {
// return false;
// }
// // unpack
// boolean success = false;
// try {
// String foldername = decompressTarGz(archive, nodeSources, false);
// assert foldername != null : version;
// success = new File(nodeSources, foldername).renameTo(new File(nodeSources, nodeVersion));
// } catch (IOException ex) {
// LOGGER.log(Level.INFO, archive.getAbsolutePath(), ex);
// throw ex;
// }
// if (!archive.delete()) {
// archive.deleteOnExit();
// }
// return success;
// }
// TODO: Determine if really need to "Delete Existing Python Source" like is done with Node js
// private static void deleteExistingNodeSources(Version version) throws IOException {
// assert version != null;
// if (PythonUtils.hasNodeSources(version)) {
// final FileObject fo = FileUtil.toFileObject(PythonUtils.getNodeSources(version));
// assert fo != null : version;
// FileUtil.runAtomicAction(new FileSystem.AtomicAction() {
// @Override
// public void run() throws IOException {
// fo.delete();
// }
// });
// }
// }
//
// @NbBundle.Messages({
// "# {0} - version",
// "FileUtils.sources.downloading.nodejs=Downloading sources for node.js version {0}...",
// "# {0} - version",
// "FileUtils.sources.downloading.iojs=Downloading sources for io.js version {0}...",
// })
// private static boolean downloadNodeSources(File archive, String nodeVersion, boolean iojs) throws IOException {
// assert archive != null;
// assert nodeVersion != null;
// String url = String.format(iojs ? JYTHON_SOURCES_URL : PYTHON_SOURCES_URL, nodeVersion);
// // download
// try {
// String msg = iojs ? Bundle.FileUtils_sources_downloading_iojs(nodeVersion) : Bundle.FileUtils_sources_downloading_nodejs(nodeVersion);
// NetworkSupport.downloadWithProgress(url, archive, msg);
// return true;
// } catch (InterruptedException ex) {
// // download cancelled
// LOGGER.log(Level.FINE, "Download cancelled for {0}", url);
// } catch (IOException ex) {
// LOGGER.log(Level.INFO, url, ex);
// throw ex;
// }
// return false;
// }
@CheckForNull
public static String decompressTarGz(File archive, File destination, boolean skipArchiveRoot) throws IOException {
String archiveRoot = null;
try (TarArchiveInputStream tarInputStream = new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(archive)))) {
int archiveRootLength = -1;
TarArchiveEntry tarEntry = tarInputStream.getNextTarEntry();
if (tarEntry != null) {
archiveRoot = tarEntry.getName();
if (skipArchiveRoot) {
archiveRootLength = archiveRoot.length();
tarEntry = tarInputStream.getNextTarEntry();
}
}
while (tarEntry != null) {
String name = tarEntry.getName();
if (skipArchiveRoot) {
name = name.substring(archiveRootLength);
}
File destPath = new File(destination, name);
if (tarEntry.isDirectory()) {
if (!destPath.isDirectory() && !destPath.mkdirs()) {
throw new IOException("Cannot create directory " + destPath);
}
} else {
if (!destPath.isFile() && !destPath.createNewFile()) {
throw new IOException("Cannot create new file " + destPath);
}
try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(destPath))) {
FileUtil.copy(tarInputStream, outputStream);
}
}
tarEntry = tarInputStream.getNextTarEntry();
}
}
return archiveRoot;
}
use of org.netbeans.api.annotations.common.CheckForNull in project python4nb by ebresie.
the class PythonExecutable method forPath.
@CheckForNull
public static PythonExecutable forPath(String path) {
ValidationResult result = new ValidationResult();
ValidationUtils.validatePython(result, path);
;
if (validateResult(result) != null) {
return null;
}
return createExecutable(path, null);
}
use of org.netbeans.api.annotations.common.CheckForNull in project netbeans-rcp-lite by outersky.
the class PluginManager method installSingle.
/**
* Open standard dialog for installing a module including declared dependencies.
* Shows it to the user, asks for confirmation, license acceptance, etc.
* The whole operation requires AWT dispatch thread access (to show the dialog)
* and blocks (until the user clicks through), so either call from AWT dispatch
* thread directly, or be sure you hold no locks and block no progress of other
* threads to avoid deadlocks.
*
* @param codenamebase the codenamebase of module to install
* @param displayName the display name of the module
* @param alternativeOptions alternative options possibly displayed in error
* dialog user may choose if it is not possible to install the plugin;
* if chosen the option is return value of this method
* @return <code>null</code> if the module has been successfully installed
* and/or activated, otherwise it returns the options user has
* selected in problem dialog, typically {@link NotifyDescriptor#DEFAULT_OPTION}
* (on esc), {@link NotifyDescriptor#CANCEL_OPTION} or
* any of <code>alternativeOptions</code>.
* @since 1.35
* @see #install(java.util.Set, java.lang.Object[])
*/
@CheckForNull
public static Object installSingle(@NonNull String codenamebase, @NonNull String displayName, @NonNull Object... alternativeOptions) {
Parameters.notNull("cnb", codenamebase);
Parameters.notNull("displayName", displayName);
Parameters.notNull("alternativeOptions", alternativeOptions);
try {
return new ModuleInstallerSupport(alternativeOptions).installPlugins(displayName, Collections.singleton(codenamebase));
} catch (OperationException ex) {
Logger.getLogger(PluginManager.class.getName()).log(Level.WARNING, null, ex);
}
return NotifyDescriptor.DEFAULT_OPTION;
}
use of org.netbeans.api.annotations.common.CheckForNull in project netbeans-rcp-lite by outersky.
the class KeyStrokeUtils method getKeyStroke.
/**
* Convert human-readable keystroke name to {@link KeyStroke} object.
*/
@CheckForNull
public static KeyStroke getKeyStroke(@NonNull String keyStroke) {
int modifiers = 0;
while (true) {
if (keyStroke.startsWith(EMACS_CTRL)) {
modifiers |= InputEvent.CTRL_DOWN_MASK;
keyStroke = keyStroke.substring(EMACS_CTRL.length());
} else if (keyStroke.startsWith(EMACS_ALT)) {
modifiers |= InputEvent.ALT_DOWN_MASK;
keyStroke = keyStroke.substring(EMACS_ALT.length());
} else if (keyStroke.startsWith(EMACS_SHIFT)) {
modifiers |= InputEvent.SHIFT_DOWN_MASK;
keyStroke = keyStroke.substring(EMACS_SHIFT.length());
} else if (keyStroke.startsWith(EMACS_META)) {
modifiers |= InputEvent.META_DOWN_MASK;
keyStroke = keyStroke.substring(EMACS_META.length());
} else if (keyStroke.startsWith(STRING_ALT)) {
modifiers |= InputEvent.ALT_DOWN_MASK;
keyStroke = keyStroke.substring(STRING_ALT.length());
} else if (keyStroke.startsWith(STRING_META)) {
modifiers |= InputEvent.META_DOWN_MASK;
keyStroke = keyStroke.substring(STRING_META.length());
} else {
break;
}
}
KeyStroke ks = Utilities.stringToKey(keyStroke);
if (ks == null) {
// Return null to indicate an invalid keystroke
return null;
} else {
KeyStroke result = KeyStroke.getKeyStroke(ks.getKeyCode(), modifiers);
return result;
}
}
use of org.netbeans.api.annotations.common.CheckForNull in project python4nb by ebresie.
the class ExternalExecutable method runInternal.
@CheckForNull
private Future<Integer> runInternal(ExecutionDescriptor executionDescriptor, ExecutionDescriptor.InputProcessorFactory2 outProcessorFactory) {
// NOI18N
Parameters.notNull("executionDescriptor", executionDescriptor);
final String error = ExternalExecutableValidator.validateCommand(executable, executableName);
if (error != null) {
if (warnUser) {
ExternalExecutableUserWarning euw = Lookup.getDefault().lookup(ExternalExecutableUserWarning.class);
if (euw == null) {
LOGGER.info("No implementation of " + ExternalExecutableUserWarning.class);
} else {
euw.displayError(error, optionsPath);
}
}
return null;
}
ProcessBuilder processBuilder = getProcessBuilder();
executionDescriptor = getExecutionDescriptor(executionDescriptor, outProcessorFactory);
return ExecutionService.newService(processBuilder, executionDescriptor, getDisplayName()).run();
}
Aggregations