use of aQute.bnd.build.Workspace in project intellij-plugins by JetBrains.
the class BndProjectImporter method findWorkspace.
/**
* Caches a workspace for methods below.
*/
@Nullable
public static Workspace findWorkspace(@NotNull com.intellij.openapi.project.Project project) {
String basePath = project.getBasePath();
if (basePath != null && new File(basePath, CNF_DIR).exists()) {
try {
Workspace ws = Workspace.getWorkspace(new File(basePath), CNF_DIR);
BND_WORKSPACE_KEY.set(project, ws);
return ws;
} catch (Exception e) {
LOG.error(e);
}
}
return null;
}
use of aQute.bnd.build.Workspace in project intellij-plugins by JetBrains.
the class BndSelectProjectsStep method initWorkspace.
private void initWorkspace() {
final BndProjectImportBuilder builder = (BndProjectImportBuilder) getContext();
Workspace workspace = builder.getWorkspace();
if (workspace != null)
return;
ProgressManager.getInstance().run(new Task.Modal(null, OsmorcBundle.message("bnd.import.progress.enumerating"), false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
String directory = getWizardContext().getProjectFileDirectory();
Workspace workspace = Workspace.getWorkspace(new File(directory), BndProjectImporter.CNF_DIR);
builder.setWorkspace(workspace, BndProjectImporter.getWorkspaceProjects(workspace));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
use of aQute.bnd.build.Workspace in project intellij-plugins by JetBrains.
the class ResolveAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
VirtualFile virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE);
Project project = event.getProject();
if (virtualFile == null || project == null)
return;
Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
if (document == null)
return;
FileDocumentManager.getInstance().saveAllDocuments();
new Task.Backgroundable(project, message("bnd.resolve.requirements.title"), true) {
private Map<Resource, List<Wire>> resolveResult;
private String updatedText;
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
File file = new File(virtualFile.getPath());
try (Workspace workspace = Workspace.findWorkspace(file);
Run run = Run.createRun(workspace, file);
ProjectResolver projectResolver = new ProjectResolver(run)) {
resolveResult = projectResolver.resolve();
List<VersionedClause> versionedClauses = projectResolver.getRunBundles().stream().map(c -> {
Attrs attrs = new Attrs();
attrs.put(Constants.VERSION_ATTRIBUTE, c.getVersion());
return new VersionedClause(c.getBundleSymbolicName(), attrs);
}).sorted(Comparator.comparing(VersionedClause::getName)).collect(Collectors.toList());
BndEditModel editModel = new BndEditModel();
IDocument bndDocument = new aQute.bnd.properties.Document(document.getImmutableCharSequence().toString());
editModel.loadFrom(bndDocument);
editModel.setRunBundles(versionedClauses);
editModel.saveChangesTo(bndDocument);
updatedText = bndDocument.get();
} catch (ProcessCanceledException e) {
throw e;
} catch (Exception e) {
throw new WrappingException(e);
}
indicator.checkCanceled();
}
@Override
public void onSuccess() {
if (new ResolutionSucceedDialog(project, resolveResult).showAndGet() && FileModificationService.getInstance().prepareVirtualFilesForWrite(project, Collections.singleton(virtualFile))) {
writeCommandAction(project).withName("Bndrun Resolve").run(() -> document.setText(updatedText));
}
}
@Override
public void onThrowable(@NotNull Throwable t) {
Throwable cause = t instanceof WrappingException ? t.getCause() : t;
LOG.warn("Resolution failed", cause);
if (cause instanceof ResolutionException) {
new ResolutionFailedDialog(project, (ResolutionException) cause).show();
} else {
OsmorcBundle.notification(message("bnd.resolve.failed.title"), cause.getMessage(), NotificationType.ERROR).notify(project);
}
}
}.queue();
}
use of aQute.bnd.build.Workspace in project intellij-plugins by JetBrains.
the class OsmorcProjectComponent method initComponent.
@Override
public void initComponent() {
MessageBusConnection connection = myProject.getMessageBus().connect();
connection.subscribe(FrameworkDefinitionListener.TOPIC, new MyFrameworkDefinitionListener());
connection.subscribe(ProjectTopics.MODULES, new MyModuleRenameHandler());
Workspace workspace = BndProjectImporter.findWorkspace(myProject);
if (workspace != null) {
connection.subscribe(VirtualFileManager.VFS_CHANGES, new MyVfsListener());
}
}
use of aQute.bnd.build.Workspace in project bnd by bndtools.
the class RunconfigToDistributionTask method execute.
@Override
public void execute() throws BuildException {
try {
createReleaseDir();
BndEditModel model = new BndEditModel();
model.loadFrom(bndFile);
Project bndProject = new Project(new Workspace(rootDir), buildProject, bndFile);
List<RepositoryPlugin> repositories = bndProject.getPlugins(RepositoryPlugin.class);
if (allowSnapshots) {
snapshots = indexBundleSnapshots();
}
for (VersionedClause runBundle : model.getRunBundles()) {
String bsn = runBundle.getName();
if (bsn.endsWith(".jar")) {
bsn = bsn.substring(0, bsn.indexOf(".jar"));
}
if (allowSnapshots && snapshots.containsKey(bsn)) {
Jar jar = snapshots.get(bsn);
jar.write(new File(outputDir, jar.getName() + "-" + jar.getVersion() + ".jar"));
} else {
Version version = null;
File foundJar = null;
for (RepositoryPlugin repo : repositories) {
SortedSet<Version> versions = repo.versions(bsn);
for (Version availableVersion : versions) {
VersionRange range = null;
if (runBundle.getVersionRange() != null && !runBundle.getVersionRange().equals(Constants.VERSION_ATTR_LATEST)) {
range = new VersionRange(runBundle.getVersionRange());
}
boolean rangeMatches = range == null || range.includes(availableVersion);
boolean availableMatches = version == null || availableVersion.compareTo(version) > 0;
if (rangeMatches && availableMatches) {
version = availableVersion;
foundJar = repo.get(bsn, version, null);
}
}
}
if (foundJar != null) {
File outputFile = new File(outputDir, foundJar.getName());
Files.copy(foundJar.toPath(), outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
} else {
log(bsn + " could not be found in any repository");
}
}
}
bndProject.close();
} catch (Exception e) {
e.printStackTrace();
throw new BuildException(e);
}
}
Aggregations