use of bndtools.preferences.BndPreferences in project bndtools by bndtools.
the class Central method getWorkspace.
public static Workspace getWorkspace() throws Exception {
if (getInstance() == null) {
throw new IllegalStateException("Central is not initialised");
}
Workspace ws;
boolean resolve;
synchronized (workspaceQueue) {
ws = workspace;
File workspaceDirectory = getWorkspaceDirectory();
if (ws != null) {
if (workspaceDirectory != null && ws.isDefaultWorkspace()) {
ws.setFileSystem(workspaceDirectory, Workspace.CNFDIR);
ws.refresh();
resolve = !workspaceQueue.getPromise().isDone();
} else if (workspaceDirectory == null && !ws.isDefaultWorkspace()) {
ws.setFileSystem(Workspace.BND_DEFAULT_WS, Workspace.CNFDIR);
ws.refresh();
resolve = false;
} else {
resolve = false;
}
} else {
try {
Workspace.setDriver(Constants.BNDDRIVER_ECLIPSE);
Workspace.addGestalt(Constants.GESTALT_INTERACTIVE, new Attrs());
if (workspaceDirectory == null) {
// there is no cnf project. So
// we create a temp workspace
ws = Workspace.createDefaultWorkspace();
resolve = false;
} else {
ws = Workspace.getWorkspace(workspaceDirectory);
resolve = true;
}
ws.setOffline(new BndPreferences().isWorkspaceOffline());
ws.addBasicPlugin(new WorkspaceListener(ws));
ws.addBasicPlugin(getInstance().repoListenerTracker);
ws.addBasicPlugin(getWorkspaceR5Repository());
ws.addBasicPlugin(new JobProgress());
// Initialize projects in synchronized block
ws.getBuildOrder();
// Monitor changes in cnf so we can refresh the workspace
addCnfChangeListener(ws);
workspaceRepositoryChangeDetector = new WorkspaceRepositoryChangeDetector(ws);
// The workspace has been initialized fully, set the field now
workspace = ws;
} catch (final Exception e) {
if (ws != null) {
ws.close();
}
throw e;
}
}
}
if (resolve)
// notify onWorkspaceInit callbacks
workspaceQueue.resolve(ws);
return ws;
}
use of bndtools.preferences.BndPreferences in project bndtools by bndtools.
the class RepositoryBundleSelectionPart method createSection.
void createSection(Section section, FormToolkit toolkit) {
// Toolbar buttons
ToolBar toolbar = new ToolBar(section, SWT.FLAT);
section.setTextClient(toolbar);
fillToolBar(toolbar);
Composite composite = toolkit.createComposite(section);
section.setClient(composite);
table = toolkit.createTable(composite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER | SWT.H_SCROLL);
viewer = new TableViewer(table);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(getLabelProvider());
// Listeners
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ToolItem remove = getRemoveItemTool();
if (remove != null)
remove.setEnabled(isRemovable(event.getSelection()));
}
});
ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
event.detail = DND.DROP_COPY;
}
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
if (FileTransfer.getInstance().isSupportedType(transferType))
return true;
if (ResourceTransfer.getInstance().isSupportedType(transferType))
return true;
if (URLTransfer.getInstance().isSupportedType(transferType))
return true;
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
return false;
}
Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
while (iterator.hasNext()) {
if (!selectionIsDroppable(iterator.next())) {
return false;
}
}
return true;
}
private boolean selectionIsDroppable(Object element) {
return element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion || element instanceof ProjectBundle || element instanceof RepositoryResourceElement;
}
@Override
public boolean performDrop(Object data) {
TransferData transfer = getCurrentEvent().currentDataType;
if (URLTransfer.getInstance().isSupportedType(transfer)) {
String urlStr = (String) URLTransfer.getInstance().nativeToJava(transfer);
return handleURLDrop(urlStr);
} else if (data instanceof String[]) {
return handleFileNameDrop((String[]) data);
} else if (data instanceof IResource[]) {
return handleResourceDrop((IResource[]) data);
} else {
return handleSelectionDrop();
}
}
private boolean handleResourceDrop(IResource[] resources) {
File[] files = new File[resources.length];
for (int i = 0; i < resources.length; i++) {
files[i] = resources[i].getLocation().toFile();
}
return handleFileDrop(files);
}
private boolean handleFileNameDrop(String[] paths) {
File[] files = new File[paths.length];
for (int i = 0; i < paths.length; i++) {
files[i] = new File(paths[i]);
}
return handleFileDrop(files);
}
private boolean handleFileDrop(File[] files) {
if (files.length > 0) {
BndPreferences prefs = new BndPreferences();
boolean hideWarning = prefs.getHideWarningExternalFile();
if (!hideWarning) {
MessageDialogWithToggle dialog = MessageDialogWithToggle.openWarning(getSection().getShell(), "Add External Files", "External files cannot be directly added to a project, they must be added to a local repository first.", "Do not show this warning again.", false, null, null);
if (Window.CANCEL == dialog.getReturnCode())
return false;
if (dialog.getToggleState()) {
prefs.setHideWarningExternalFile(true);
}
}
AddFilesToRepositoryWizard wizard = new AddFilesToRepositoryWizard(null, files);
WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
if (Window.OK == dialog.open()) {
List<Pair<String, String>> addingBundles = wizard.getSelectedBundles();
List<VersionedClause> addingClauses = new ArrayList<VersionedClause>(addingBundles.size());
for (Pair<String, String> addingBundle : addingBundles) {
Attrs attribs = new Attrs();
attribs.put(Constants.VERSION_ATTRIBUTE, addingBundle.getSecond());
addingClauses.add(new VersionedClause(addingBundle.getFirst(), attribs));
}
handleAdd(addingClauses);
}
return true;
}
return false;
}
private boolean handleSelectionDrop() {
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
return false;
}
List<VersionedClause> adding = new LinkedList<VersionedClause>();
Iterator<?> iterator = ((IStructuredSelection) selection).iterator();
while (iterator.hasNext()) {
Object item = iterator.next();
if (item instanceof RepositoryBundle) {
VersionedClause newClause = RepositoryBundleUtils.convertRepoBundle((RepositoryBundle) item);
adding.add(newClause);
} else if (item instanceof RepositoryBundleVersion) {
RepositoryBundleVersion bundleVersion = (RepositoryBundleVersion) item;
VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(bundleVersion, phase);
adding.add(newClause);
} else if (item instanceof RepositoryResourceElement) {
RepositoryResourceElement elt = (RepositoryResourceElement) item;
VersionedClause newClause = RepositoryBundleUtils.convertRepoBundleVersion(elt.getRepositoryBundleVersion(), phase);
adding.add(newClause);
}
}
handleAdd(adding);
return true;
}
private boolean handleURLDrop(String urlStr) {
try {
URI uri = new URI(sanitizeUrl(urlStr));
AddJpmDependenciesWizard wizard = new AddJpmDependenciesWizard(uri);
WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
if (dialog.open() == Window.OK) {
Set<ResourceDescriptor> resources = wizard.getResult();
List<VersionedClause> newBundles = new ArrayList<VersionedClause>(resources.size());
for (ResourceDescriptor resource : resources) {
Attrs attrs = new Attrs();
attrs.put(Constants.VERSION_ATTRIBUTE, resource.version != null ? resource.version.toString() : Version.emptyVersion.toString());
VersionedClause clause = new VersionedClause(resource.bsn, attrs);
newBundles.add(clause);
}
handleAdd(newBundles);
return true;
}
return false;
} catch (URISyntaxException e) {
MessageDialog.openError(getSection().getShell(), "Error", "The dropped URL was invalid: " + urlStr);
return false;
}
}
private String sanitizeUrl(String urlStr) {
int newline = urlStr.indexOf('\n');
if (newline > -1)
return urlStr.substring(0, newline).trim();
return urlStr;
}
private void handleAdd(Collection<VersionedClause> newClauses) {
if (newClauses == null || newClauses.isEmpty())
return;
List<VersionedClause> toAdd = new LinkedList<VersionedClause>();
for (VersionedClause newClause : newClauses) {
boolean found = false;
for (ListIterator<VersionedClause> iter = bundles.listIterator(); iter.hasNext(); ) {
VersionedClause existing = iter.next();
if (newClause.getName().equals(existing.getName())) {
int index = iter.previousIndex();
iter.set(newClause);
viewer.replace(newClause, index);
found = true;
break;
}
}
if (!found)
toAdd.add(newClause);
}
bundles.addAll(toAdd);
viewer.add(toAdd.toArray());
markDirty();
}
};
dropAdapter.setFeedbackEnabled(false);
dropAdapter.setExpandEnabled(false);
viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), URLTransfer.getInstance() }, dropAdapter);
table.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.character == SWT.DEL) {
doRemove();
} else if (e.character == '+') {
doAdd();
}
}
});
// Layout
GridLayout layout = new GridLayout(1, false);
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.widthHint = 50;
gd.heightHint = getTableHeightHint();
table.setLayoutData(gd);
}
use of bndtools.preferences.BndPreferences in project bndtools by bndtools.
the class BndtoolsBuilder method build.
/**
* Called from Eclipse when it thinks this project should be build. We're proposed to figure out if we've changed
* and then build as quickly as possible.
* <p>
* We ensure we're called in proper order defined by bnd, if not we will make it be called in proper order.
*
* @param kind
* @param args
* @param monitor
* @return List of projects we depend on
*/
@Override
protected IProject[] build(final int kind, Map<String, String> args, final IProgressMonitor monitor) throws CoreException {
BndPreferences prefs = new BndPreferences();
buildLog = new BuildLogger(prefs.getBuildLogging());
final BuildListeners listeners = new BuildListeners();
final IProject myProject = getProject();
try {
listeners.fireBuildStarting(myProject);
final MarkerSupport markers = new MarkerSupport(myProject);
if (dependsOn == null) {
dependsOn = myProject.getDescription().getDynamicReferences();
}
if (model == null) {
try {
model = Central.getProject(myProject);
} catch (Exception e) {
markers.deleteMarkers("*");
}
if (model == null)
return noreport();
}
try {
return Central.bndCall(new Callable<IProject[]>() {
@Override
public IProject[] call() throws Exception {
boolean force = kind == FULL_BUILD || kind == CLEAN_BUILD;
model.clear();
DeltaWrapper delta = new DeltaWrapper(model, getDelta(myProject), buildLog);
boolean setupChanged = false;
if (!postponed && (delta.havePropertiesChanged(model) || delta.hasChangedSubbundles())) {
buildLog.basic("project was dirty from changed bnd files postponed = " + postponed);
model.forceRefresh();
setupChanged = true;
}
if (dirty.remove(model)) {
buildLog.basic("project was dirty from a workspace refresh postponed = " + postponed);
setupChanged = true && !postponed;
}
if (!force && !setupChanged && delta.hasEclipseChanged()) {
buildLog.basic("Eclipse project had a buildpath change");
setupChanged = true;
}
if (!force && !setupChanged && suggestClasspathContainerUpdate()) {
buildLog.basic("Project classpath may need to be updated");
setupChanged = true;
}
if (force || setupChanged) {
model.setChanged();
model.setDelayRunDependencies(true);
model.prepare();
markers.validate(model);
markers.setMarkers(model, BndtoolsConstants.MARKER_BND_PATH_PROBLEM);
model.clear();
dependsOn = calculateDependsOn(model);
//
// We have a setup change so we MUST check both class path
// changes and build order changes. Careful not to use an OR
// operation (as I did) because they are shortcutted. Since it
// is also nice to see why we had a change, we just collect the
// reason of the change so we can report it to the log.
//
// if empty, no change
String changed = "";
String del = "";
if (requestClasspathContainerUpdate()) {
changed += "Classpath container updated";
del = " & ";
}
if (setBuildOrder(monitor)) {
changed += del + "Build order changed";
}
if (!changed.equals("")) {
buildLog.basic("Setup changed: " + changed);
return postpone();
}
force = true;
}
//
if (postponed)
buildLog.full("Was postponed");
force |= postponed;
postponed = false;
if (!force && delta.hasProjectChanged()) {
buildLog.basic("project had changed files");
force = true;
}
if (!force && hasUpstreamChanges()) {
buildLog.basic("project had upstream changes");
force = true;
}
if (!force && delta.hasNoTarget(model)) {
buildLog.basic("project has no target files");
force = true;
}
if (!force) {
buildLog.full("Auto/Incr. build, no changes detected");
return noreport();
}
WorkingSetTracker.doWorkingSets(model, myProject);
if (model.isNoBundles()) {
buildLog.basic("-nobundles was set, so no build");
buildLog.setFiles(0);
return report(markers);
}
if (markers.hasBlockingErrors(delta)) {
CompileErrorAction actionOnCompileError = getActionOnCompileError();
if (actionOnCompileError != CompileErrorAction.build) {
if (actionOnCompileError == CompileErrorAction.delete) {
buildLog.basic("Blocking errors, delete build files, quit");
deleteBuildFiles(model);
model.error("Will not build project %s until the compilation and/or path problems are fixed, output files are deleted.", myProject.getName());
} else {
buildLog.basic("Blocking errors, leave old build files, quit");
model.error("Will not build project %s until the compilation and/or path problems are fixed, output files are kept.", myProject.getName());
}
return report(markers);
}
buildLog.basic("Blocking errors, continuing anyway");
model.warning("Project %s has blocking errors but requested to continue anyway", myProject.getName());
}
Central.invalidateIndex();
File[] buildFiles = model.build();
if (buildFiles != null) {
listeners.updateListeners(buildFiles, myProject);
buildLog.setFiles(buildFiles.length);
}
// We can now decorate based on the build we just did.
PackageDecorator.updateDecoration(myProject, model);
ComponentMarker.updateComponentMarkers(myProject, model);
if (model.isCnf()) {
// this is for bnd plugins built in cnf
model.getWorkspace().refresh();
}
return report(markers);
}
}, monitor);
} catch (TimeoutException | InterruptedException e) {
logger.logWarning("Unable to build project " + myProject.getName(), e);
return postpone();
}
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, 0, "Build Error!", e));
} finally {
if (buildLog.isActive())
logger.logInfo(buildLog.toString(myProject.getName()), null);
listeners.release(myProject);
}
}
use of bndtools.preferences.BndPreferences in project bndtools by bndtools.
the class GeneratedResourcesPreferencePage method init.
@Override
public void init(IWorkbench workbench) {
BndPreferences prefs = new BndPreferences();
enableSubs = prefs.getEnableSubBundles();
noAskPackageInfo = prefs.getNoAskPackageInfo();
headlessBuildCreate = prefs.getHeadlessBuildCreate();
Collection<NamedPlugin> pluginsInformation = headlessBuildManager.getAllPluginsInformation();
if (pluginsInformation.size() > 0) {
headlessBuildPlugins.clear();
headlessBuildPlugins.putAll(prefs.getHeadlessBuildPlugins(pluginsInformation, false));
}
versionControlIgnoresCreate = prefs.getVersionControlIgnoresCreate();
pluginsInformation = versionControlIgnoresManager.getAllPluginsInformation();
if (pluginsInformation.size() > 0) {
versionControlIgnoresPlugins.clear();
versionControlIgnoresPlugins.putAll(prefs.getVersionControlIgnoresPlugins(versionControlIgnoresManager.getAllPluginsInformation(), false));
}
}
use of bndtools.preferences.BndPreferences in project bndtools by bndtools.
the class BndPreferencePage method init.
@Override
public void init(IWorkbench workbench) {
BndPreferences prefs = new BndPreferences();
noCheckCnf = prefs.getHideInitCnfWizard();
warnExistingLaunch = prefs.getWarnExistingLaunches();
buildBeforeLaunch = prefs.getBuildBeforeLaunch();
editorOpenSourceTab = prefs.getEditorOpenSourceTab();
workspaceIsOffline = prefs.isWorkspaceOffline();
}
Aggregations