use of org.jetbrains.jps.model.JpsModel in project intellij-community by JetBrains.
the class JpsSerializationManagerImpl method loadModel.
@NotNull
@Override
public JpsModel loadModel(@NotNull String projectPath, @Nullable String optionsPath) throws IOException {
JpsModel model = JpsElementFactory.getInstance().createModel();
if (optionsPath != null) {
JpsGlobalLoader.loadGlobalSettings(model.getGlobal(), optionsPath);
}
Map<String, String> pathVariables = JpsModelSerializationDataService.computeAllPathVariables(model.getGlobal());
JpsProjectLoader.loadProject(model.getProject(), pathVariables, projectPath);
return model;
}
use of org.jetbrains.jps.model.JpsModel in project intellij-community by JetBrains.
the class Standalone method loadAndRunBuild.
public int loadAndRunBuild(final String projectPath) {
String globalOptionsPath = null;
if (configPath != null) {
File optionsDir = new File(configPath, "options");
if (!optionsDir.isDirectory()) {
System.err.println("'" + configPath + "' is not valid config path: " + optionsDir.getAbsolutePath() + " not found");
return 1;
}
globalOptionsPath = optionsDir.getAbsolutePath();
}
ParameterizedRunnable<JpsModel> initializer = null;
String scriptPath = initializationScriptPath;
if (scriptPath != null) {
File scriptFile = new File(scriptPath);
if (!scriptFile.isFile()) {
System.err.println("Script '" + scriptPath + "' not found");
return 1;
}
initializer = new GroovyModelInitializer(scriptFile);
}
if (modules.length == 0 && artifacts.length == 0 && !allModules && !allArtifacts) {
System.err.println("Nothing to compile: at least one of --modules, --artifacts, --all-modules or --all-artifacts parameters must be specified");
return 1;
}
JpsModelLoaderImpl loader = new JpsModelLoaderImpl(projectPath, globalOptionsPath, initializer);
Set<String> modulesSet = new HashSet<>(Arrays.asList(modules));
List<String> artifactsList = Arrays.asList(artifacts);
File dataStorageRoot;
if (cacheDirPath != null) {
dataStorageRoot = new File(cacheDirPath);
} else {
dataStorageRoot = Utils.getDataStorageRoot(projectPath);
}
if (dataStorageRoot == null) {
System.err.println("Error: Cannot determine build data storage root for project " + projectPath);
return 1;
}
ConsoleMessageHandler consoleMessageHandler = new ConsoleMessageHandler();
long start = System.currentTimeMillis();
try {
runBuild(loader, dataStorageRoot, !incremental, modulesSet, allModules, artifactsList, allArtifacts, true, consoleMessageHandler);
} catch (Throwable t) {
System.err.println("Internal error: " + t.getMessage());
t.printStackTrace();
}
System.out.println("Build finished in " + Utils.formatDuration(System.currentTimeMillis() - start));
return consoleMessageHandler.hasErrors() ? 1 : 0;
}
use of org.jetbrains.jps.model.JpsModel in project intellij-community by JetBrains.
the class JpsEncodingProjectConfigurationImpl method getEncoding.
@Nullable
@Override
public String getEncoding(@NotNull File file) {
if (isXmlFile(file)) {
try {
String encoding = XmlCharsetDetector.extractXmlEncodingFromProlog(FileUtil.loadFileBytes(file));
if (encoding != null) {
return encoding;
}
} catch (IOException e) {
LOG.info("Cannot detect encoding for xml file " + file.getAbsolutePath(), e);
}
}
if (!myUrlToEncoding.isEmpty()) {
File current = file;
while (current != null) {
String encoding = myUrlToEncoding.get(JpsPathUtil.pathToUrl(FileUtilRt.toSystemIndependentName(current.getPath())));
if (encoding != null) {
return encoding;
}
current = FileUtilRt.getParentFile(current);
}
}
if (myProjectEncoding != null) {
return myProjectEncoding;
}
final JpsModel model = getModel();
assert model != null;
return JpsEncodingConfigurationService.getInstance().getGlobalEncoding(model.getGlobal());
}
use of org.jetbrains.jps.model.JpsModel in project intellij-community by JetBrains.
the class JpsModelLoaderImpl method loadModel.
@Override
public JpsModel loadModel() throws IOException {
final long start = System.currentTimeMillis();
LOG.info("Loading model: project path = " + myProjectPath + ", global options path = " + myGlobalOptionsPath);
final JpsModel model = JpsSerializationManager.getInstance().loadModel(myProjectPath, myGlobalOptionsPath);
if (myModelInitializer != null) {
myModelInitializer.run(model);
}
final long loadTime = System.currentTimeMillis() - start;
LOG.info("Model loaded in " + loadTime + " ms");
LOG.info("Project has " + model.getProject().getModules().size() + " modules, " + model.getProject().getLibraryCollection().getLibraries().size() + " libraries");
return model;
}
use of org.jetbrains.jps.model.JpsModel in project intellij-community by JetBrains.
the class IdeaJdk method setupSdkPathsFromIDEAProject.
private static void setupSdkPathsFromIDEAProject(Sdk sdk, SdkModificator sdkModificator, SdkModel sdkModel) throws IOException {
ProgressIndicator indicator = ObjectUtils.assertNotNull(ProgressManager.getInstance().getProgressIndicator());
String sdkHome = ObjectUtils.notNull(sdk.getHomePath());
JpsModel model = JpsSerializationManager.getInstance().loadModel(sdkHome, PathManager.getOptionsPath());
JpsSdkReference<JpsDummyElement> sdkRef = model.getProject().getSdkReferencesTable().getSdkReference(JpsJavaSdkType.INSTANCE);
String sdkName = sdkRef == null ? null : sdkRef.getSdkName();
Sdk internalJava = sdkModel.findSdk(sdkName);
if (internalJava != null && isValidInternalJdk(sdk, internalJava)) {
setInternalJdk(sdk, sdkModificator, internalJava);
}
Set<VirtualFile> addedRoots = ContainerUtil.newTroveSet();
VirtualFileManager vfsManager = VirtualFileManager.getInstance();
JpsJavaExtensionService javaService = JpsJavaExtensionService.getInstance();
boolean isUltimate = vfsManager.findFileByUrl(VfsUtilCore.pathToUrl(sdkHome + "/ultimate/ultimate-resources")) != null;
Set<String> suppressedModules = ContainerUtil.newTroveSet("jps-plugin-system");
Set<String> ultimateModules = ContainerUtil.newTroveSet("platform-ultimate", "ultimate-resources", "ultimate-verifier", "diagram-api", "diagram-impl", "uml-plugin");
List<JpsModule> modules = JBIterable.from(model.getProject().getModules()).filter(o -> {
if (suppressedModules.contains(o.getName()))
return false;
if (o.getName().endsWith("-ide"))
return false;
String contentUrl = ContainerUtil.getFirstItem(o.getContentRootsList().getUrls());
if (contentUrl == null)
return true;
return !isUltimate || contentUrl.contains("/community/") || ultimateModules.contains(o.getName());
}).toList();
indicator.setIndeterminate(false);
double delta = 1 / (2 * Math.max(0.5, modules.size()));
for (JpsModule o : modules) {
indicator.setFraction(indicator.getFraction() + delta);
for (JpsDependencyElement dep : o.getDependenciesList().getDependencies()) {
ProgressManager.checkCanceled();
JpsLibrary library = dep instanceof JpsLibraryDependency ? ((JpsLibraryDependency) dep).getLibrary() : null;
JpsLibraryType<?> libraryType = library == null ? null : library.getType();
if (!(libraryType instanceof JpsJavaLibraryType))
continue;
JpsJavaDependencyExtension extension = javaService.getDependencyExtension(dep);
if (extension == null)
continue;
// do not check extension.getScope(), plugin projects need tests too
for (JpsLibraryRoot jps : library.getRoots(JpsOrderRootType.COMPILED)) {
VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
if (root == null || !addedRoots.add(root))
continue;
sdkModificator.addRoot(root, OrderRootType.CLASSES);
}
for (JpsLibraryRoot jps : library.getRoots(JpsOrderRootType.SOURCES)) {
VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
if (root == null || !addedRoots.add(root))
continue;
sdkModificator.addRoot(root, OrderRootType.SOURCES);
}
}
}
for (JpsModule o : modules) {
indicator.setFraction(indicator.getFraction() + delta);
String outputUrl = javaService.getOutputUrl(o, false);
VirtualFile outputRoot = outputUrl == null ? null : vfsManager.findFileByUrl(outputUrl);
if (outputRoot == null)
continue;
sdkModificator.addRoot(outputRoot, OrderRootType.CLASSES);
for (JpsModuleSourceRoot jps : o.getSourceRoots()) {
ProgressManager.checkCanceled();
VirtualFile root = vfsManager.findFileByUrl(jps.getUrl());
if (root == null || !addedRoots.add(root))
continue;
sdkModificator.addRoot(root, OrderRootType.SOURCES);
}
}
indicator.setFraction(1.0);
}
Aggregations