Skip to content

Commit

Permalink
[526173] Create platforms decorator and add Remove action to Project …
Browse files Browse the repository at this point in the history
…Explorer

Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=526173

Signed-off-by: Rastislav Wagner <rawagner@redhat.com>
  • Loading branch information
rawagner committed Oct 23, 2017
1 parent 7564cbc commit db8a390
Show file tree
Hide file tree
Showing 29 changed files with 1,056 additions and 224 deletions.
Expand Up @@ -18,100 +18,100 @@
import org.eclipse.thym.core.engine.internal.cordova.DownloadableCordovaEngine;

import com.github.zafarkhaja.semver.Version;

/**
* A cordova platform engine.
* A cordova platform engine.
*
* @author Gorkem Ercan
*
*/
public class HybridMobileEngine{
private String name;
private String spec;
private HybridMobileLibraryResolver resolver;
public HybridMobileEngine(String name, String spec, HybridMobileLibraryResolver resolver) {
public class HybridMobileEngine {

private String name;
private String spec;
private HybridMobileLibraryResolver resolver;

public HybridMobileEngine(String name, String spec, HybridMobileLibraryResolver resolver) {
this.name = name;
this.spec = spec;
this.resolver = resolver;
}

/**
* User friendly name
* @return
*/

/**
* User friendly name
*
* @return
*/
public String getName() {
return name;
}
public String getSpec() {
return spec;
}

public boolean isValid(){
if(spec == null){
return false;
}
//check local - needs a better check (is this dir actually a cordova platform?)
File file = new File(spec);
if(file.exists()){
return true;
}

//check downloadable
Version version = null;
try{
version = Version.valueOf(spec);
} catch (Exception e) {
return name;
}

public String getSpec() {
return spec;
}

public boolean isValid() {
if (spec == null) {
return false;
}
if(version != null){
try {
List<DownloadableCordovaEngine> downloadableEngines =
CordovaEngineProvider.getInstance().getDownloadableEngines();
for(DownloadableCordovaEngine dEngine: downloadableEngines){
if(dEngine.getPlatformId().equals(name) && dEngine.getVersion().equals(spec)){
return true;
}
}
return false;
// check local - needs a better check (is this dir actually a cordova platform?)
File file = new File(spec);
if (file.exists()) {
return true;
}

// check downloadable
Version version = null;
try {
version = Version.valueOf(spec);
} catch (Exception e) {
return false;
}
if (version != null) {
try {
List<DownloadableCordovaEngine> downloadableEngines = CordovaEngineProvider.getInstance()
.getDownloadableEngines();
for (DownloadableCordovaEngine dEngine : downloadableEngines) {
if (dEngine.getPlatformId().equals(name) && dEngine.getVersion().equals(spec)) {
return true;
}
}
return false;
} catch (CoreException e) {
return false;
}
}
//TODO git
return false;
}

public HybridMobileLibraryResolver getResolver() {
return resolver;
}

@Override
public boolean equals(Object obj) {
if(obj == null || !(obj instanceof HybridMobileEngine) ){
return false;
}
HybridMobileEngine that = (HybridMobileEngine) obj;
if(this.getName().equals(that.getName())
&& this.getSpec().equals(that.getSpec())){
return true;
}
return super.equals(obj);
}

@Override
public int hashCode() {
if(this.getName() != null && this.getSpec() != null ){
return this.getName().hashCode()+this.getSpec().hashCode();
}
return super.hashCode();
}

@Override
public String toString() {
return this.getClass().getSimpleName() + "[ name: " + getName()
+" spec: " + getSpec() +" ]";
}
}
// TODO git
return false;
}

public HybridMobileLibraryResolver getResolver() {
return resolver;
}

@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof HybridMobileEngine)) {
return false;
}
HybridMobileEngine that = (HybridMobileEngine) obj;
if (this.getName().equals(that.getName()) && this.getSpec().equals(that.getSpec())) {
return true;
}
return super.equals(obj);
}

@Override
public int hashCode() {
if (this.getName() != null && this.getSpec() != null) {
return this.getName().hashCode() + this.getSpec().hashCode();
}
return super.hashCode();
}

@Override
public String toString() {
return this.getClass().getSimpleName() + "[ name: " + getName() + " spec: " + getSpec() + " ]";
}


}
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
Expand All @@ -43,6 +44,7 @@
import org.eclipse.thym.core.internal.util.EngineUtils;
import org.eclipse.thym.core.internal.cordova.ErrorDetectingCLIResult;
import org.eclipse.thym.core.platform.PlatformConstants;
import org.eclipse.thym.core.plugin.PluginMessagesCLIResult;

import com.google.gson.JsonElement;
import com.google.gson.JsonIOException;
Expand Down Expand Up @@ -106,6 +108,26 @@ public HybridMobileEngine[] getEngines(){
}
return new HybridMobileEngine[0];
}

public void removeEngine(HybridMobileEngine engine, IProgressMonitor monitor, boolean save) throws OperationCanceledException, CoreException {
if(monitor == null ) {
monitor = new NullProgressMonitor();
}
SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
subMonitor.setTaskName("Removing platform: " + engine);
String options ="";
if(save){
options = CordovaProjectCLI.OPTION_SAVE;
}
IStatus status = project.getProjectCLI()
.platform(Command.REMOVE, subMonitor.split(90), engine.getName(), options)
.convertTo(PluginMessagesCLIResult.class)
.asStatus();
project.getProject().refreshLocal(IResource.DEPTH_INFINITE, subMonitor.split(10, SubMonitor.SUPPRESS_ALL_LABELS));
if(!status.isOK()){
throw new CoreException(status);
}
}

/**
* Returns the active engines for the project by looking at
Expand Down Expand Up @@ -168,7 +190,7 @@ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
WidgetModel model = WidgetModel.getModel(project);
Widget w = model.getWidgetForEdit();
List<Engine> existingEngines = w.getEngines();
CordovaProjectCLI cordova = CordovaProjectCLI.newCLIforProject(project);
CordovaProjectCLI cordova = project.getProjectCLI();
SubMonitor sm = SubMonitor.convert(monitor,100);
if(existingEngines != null ){
List<HybridMobileEngine> enginesList = Arrays.asList(engines);
Expand Down Expand Up @@ -216,7 +238,7 @@ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
return new Status(IStatus.WARNING, HybridCore.PLUGIN_ID, err);
}
HybridMobileEngine[] activeEngines = getEnginesFromPlatformsJson();
CordovaProjectCLI cordova = CordovaProjectCLI.newCLIforProject(project);
CordovaProjectCLI cordova = project.getProjectCLI();
MultiStatus status = new MultiStatus(HybridCore.PLUGIN_ID, 0,
"Errors updating engines from config.xml", null);
IStatus subStatus = Status.OK_STATUS;
Expand Down
Expand Up @@ -14,19 +14,17 @@
import java.util.Collections;
import java.util.List;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
import org.eclipse.thym.core.HybridCore;
import org.eclipse.thym.core.engine.HybridMobileEngine;

import com.github.zafarkhaja.semver.Version;

public class CordovaPlugin extends PlatformObject{
public class CordovaPlugin {

private class EngineDefinition {
String name;
String version;
Expand All @@ -43,7 +41,6 @@ private class EngineDefinition {
private List<EngineDefinition> supportedEngines;
private String info;
private List<PluginJavaScriptModule> modules;
private IFolder folder;

public String getVersion() {
return version;
Expand Down Expand Up @@ -109,10 +106,9 @@ public void addSupportedEngine(String name, String version, String platform) {
engine.name = name;
engine.version = version;
engine.platform = platform;

supportedEngines.add(engine);
}


public List<PluginJavaScriptModule> getModules() {
if (modules == null)
Expand All @@ -134,67 +130,63 @@ public String getInfo() {
public void setInfo(String info) {
this.info = info;
}

public IFolder getFolder(){
return folder;
}

public void setFolder(IFolder adapter) {
this.folder = adapter;
}

/**
* Checks if the given engine is compatible with this plug-in.
* Returns a {@link MultiStatus} as there may be more than one
* reason for an engine to fail.
* Checks if the given engine is compatible with this plug-in. Returns a
* {@link MultiStatus} as there may be more than one reason for an engine to
* fail.
*
* @param engine
* @return A WARNING or OK level status
*
*/
public IStatus isEngineCompatible(HybridMobileEngine engine) {
if(supportedEngines == null || supportedEngines.isEmpty() )
if (supportedEngines == null || supportedEngines.isEmpty())
return Status.OK_STATUS;
MultiStatus status = new MultiStatus(HybridCore.PLUGIN_ID, 0, NLS.bind("Plug-in {0} is not compatible with {1} version {2}" , new Object[] {getLabel(), engine.getName(), engine.getSpec()}),null);
MultiStatus status = new MultiStatus(HybridCore.PLUGIN_ID, 0,
NLS.bind("Plug-in {0} is not compatible with {1} version {2}",
new Object[] { getLabel(), engine.getName(), engine.getSpec() }),
null);
for (EngineDefinition definition : supportedEngines) {
status.add(isDefinitionSatisfied(definition, engine));
}
return status;
}
private IStatus isDefinitionSatisfied(EngineDefinition definition, HybridMobileEngine engine){

private IStatus isDefinitionSatisfied(EngineDefinition definition, HybridMobileEngine engine) {
String reason;
if(engine.getName().equals(definition.name)){// Engine ids match
if (engine.getName().equals(definition.name)) {// Engine ids match
Version engineVer = Version.valueOf(engine.getSpec());
if(engineVer.satisfies(definition.version)){ // version is satisfied
return Status.OK_STATUS;
}else{
reason = "engine version: "+definition.version;
if (engineVer.satisfies(definition.version)) { // version is satisfied
return Status.OK_STATUS;
} else {
reason = "engine version: " + definition.version;
}
}else{
reason = "engine id: "+definition.name;

} else {
reason = "engine id: " + definition.name;
}
return new Status(IStatus.WARNING, HybridCore.PLUGIN_ID,
NLS.bind("Plug-in {0} does not support {1} version {2}. Fails version requirement: {3}",new Object[]{getLabel(),engine.getName(), engine.getSpec(), reason}));
return new Status(IStatus.WARNING, HybridCore.PLUGIN_ID,
NLS.bind("Plug-in {0} does not support {1} version {2}. Fails version requirement: {3}",
new Object[] { getLabel(), engine.getName(), engine.getSpec(), reason }));
}

/**
* Returns a label for the plug-in that can best be
* presented.
* Returns a label for the plug-in that can best be presented.
*
* @return a label string
*/
public String getLabel(){
return getName() != null ?getName() : getId();
public String getLabel() {
return getName() != null ? getName() : getId();
}

@Override
public String toString() {
if(getId() == null )
if (getId() == null)
return super.toString();
return getId()+(getVersion() ==null?"":"("+ getVersion()+")");
return getId() + (getVersion() == null ? "" : "(" + getVersion() + ")");
}

@Override
public int hashCode() {
return this.getId().hashCode();
Expand All @@ -209,6 +201,4 @@ public boolean equals(Object obj) {
return super.equals(obj);
}



}

0 comments on commit db8a390

Please sign in to comment.