public NbProjectInfo loadInfo(File project, String... extraArgs) { NbProjectInfo ret = null; GradleConnector gconn = GradleConnector.newConnector(); ProjectConnection pconn = gconn.forProjectDirectory(project).connect(); BuildActionExecuter<NbProjectInfo> action = pconn.action(new NbProjectInfoAction()); action.setJvmArguments( "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006", "-DNETBEANS_TOOLING_JAR=" + buildDir + "/libs/netbeans-gradle-tooling.jar" ); ArrayList<String> args = new ArrayList<>(); args.add("-I"); args.add(buildDir + "/resources/main/nb-tooling.gradle"); args.addAll(Arrays.asList(extraArgs)); action.withArguments(args.toArray(new String[args.size()])); try { ret = action.run(); } catch (GradleConnectionException | IllegalStateException ex) { System.err.println("Failed to retrieve project information for: " + project); ex.printStackTrace(); } finally { try { pconn.close(); } catch (NullPointerException ex) { } } return ret; }
@Override @SuppressWarnings("unchecked") public T run() throws GradleConnectionException, IllegalStateException { Object cachedValue = this.cacheKey.isInvalid() ? null : this.cache.getIfPresent(this.cacheKey); if (cachedValue != null) { return (T) cachedValue; } else { T result = this.delegate.run(); this.cache.put(this.cacheKey, result); return result; } }
@Override public Collection<T> call() throws Exception { BuildAction<Collection<T>> query = BuildActionUtil.compositeModelQuery(model); return DefaultModelProvider.this.gradleBuild.withConnection(connection -> connection.action(query).run(), monitor); } }, fetchStrategy, cacheKey);
@Override @SuppressWarnings("unchecked") public void run(ResultHandler<? super T> handler) throws IllegalStateException { Object cachedValue = this.cacheKey.isInvalid() ? null : this.cache.getIfPresent(this.cacheKey); if (cachedValue != null) { handler.onComplete((T) cachedValue); } else { InspectableResultHandler<T> inspectableResultHandler = new InspectableResultHandler<>(); this.delegate.run(inspectableResultHandler); inspectableResultHandler.getResult().ifPresent(r -> this.cache.put(this.cacheKey, r)); inspectableResultHandler.forwardResults(handler); } } }
@Override public void init(InitializationContext context, IProgressMonitor monitor) { GradleBuild gradleBuild = context.getGradleBuild(); try { Collection<EclipseProject> rootModels = gradleBuild.withConnection(connection -> connection.action(BuildActionUtil.compositeModelQuery(EclipseProject.class)).run(), monitor); this.locationToProject = rootModels.stream() .map(p -> ModelUtils.createCompatibilityModel(p)) .flatMap(p -> HierarchicalElementUtils.getAll(p).stream()) .collect(Collectors.toMap(p -> p.getProjectDirectory(), p -> p)); } catch (Exception e) { context.error("Cannot Query Eclipse model", e); } }
action.setJavaHome(jdkHome); atm = action.run();
return transformActionModels(executer.run()); } finally { initScriptRef.close();