diff --git a/bundles/org.eclipse.passage.ldc.pde.core.templates/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.ldc.pde.core.templates/META-INF/MANIFEST.MF index 546a8eae7..0a0a58059 100644 --- a/bundles/org.eclipse.passage.ldc.pde.core.templates/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.ldc.pde.core.templates/META-INF/MANIFEST.MF @@ -6,5 +6,10 @@ Bundle-Version: 0.1.0.qualifier Bundle-Name: %Bundle-Name Bundle-Vendor: %Bundle-Vendor Bundle-RequiredExecutionEnvironment: JavaSE-11 -Require-Bundle: org.eclipse.passage.lic.base;bundle-version="0.0.0" -Export-Package: org.eclipse.passage.ldc.internal.pde.core.templates;x-friends:="org.eclipse.passage.ldc.pde.ui.templates" +Require-Bundle: org.eclipse.osgi;bundle-version="0.0.0", + org.eclipse.passage.lic.base;bundle-version="0.0.0", + org.eclipse.pde.core;bundle-version="0.0.0" +Export-Package: org.eclipse.passage.ldc.internal.pde.core.templates;x-friends:="org.eclipse.passage.ldc.pde.ui.templates", + org.eclipse.passage.ldc.internal.pde.core.templates.dev;x-friends:="org.eclipse.passage.ldc.pde.ui.templates", + org.eclipse.passage.ldc.internal.pde.core.templates.features;x-friends:="org.eclipse.passage.ldc.pde.ui.templates", + org.eclipse.passage.ldc.internal.pde.core.templates.products;x-friends:="org.eclipse.passage.ldc.pde.ui.templates" diff --git a/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/OptionDefinition.java b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/OptionDefinition.java new file mode 100644 index 000000000..4a05cf6eb --- /dev/null +++ b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/OptionDefinition.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.ldc.internal.pde.core.templates; + +import java.util.Optional; + +public interface OptionDefinition { + + String id(); + + String label(); + + Optional initial(); + + Class type(); + +} diff --git a/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/OptionId.java b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/OptionId.java new file mode 100644 index 000000000..8bd03e40b --- /dev/null +++ b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/OptionId.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.ldc.internal.pde.core.templates; + +@FunctionalInterface +public interface OptionId { + + String id(); + +} diff --git a/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/TemplateId.java b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/TemplateId.java new file mode 100644 index 000000000..8914e3aea --- /dev/null +++ b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/TemplateId.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.ldc.internal.pde.core.templates; + +@FunctionalInterface +public interface TemplateId { + + String id(); + +} diff --git a/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/dev/DevMinimalTemplateId.java b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/dev/DevMinimalTemplateId.java new file mode 100644 index 000000000..666719a6e --- /dev/null +++ b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/dev/DevMinimalTemplateId.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.ldc.internal.pde.core.templates.dev; + +import org.eclipse.passage.ldc.internal.pde.core.templates.TemplateId; + +public final class DevMinimalTemplateId implements TemplateId { + + @Override + public String id() { + return "dev_minimal"; //$NON-NLS-1$ + } + +} diff --git a/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/features/FeatureIdentifierOptionId.java b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/features/FeatureIdentifierOptionId.java new file mode 100644 index 000000000..33cb72237 --- /dev/null +++ b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/features/FeatureIdentifierOptionId.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.ldc.internal.pde.core.templates.features; + +import org.eclipse.passage.ldc.internal.pde.core.templates.OptionId; + +public final class FeatureIdentifierOptionId implements OptionId { + + @Override + public String id() { + return "featureIdentifier"; //$NON-NLS-1$ + } + +} diff --git a/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/features/FeatureNameOptionId.java b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/features/FeatureNameOptionId.java new file mode 100644 index 000000000..3a52ee6c4 --- /dev/null +++ b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/features/FeatureNameOptionId.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.ldc.internal.pde.core.templates.features; + +import org.eclipse.passage.ldc.internal.pde.core.templates.OptionId; + +public final class FeatureNameOptionId implements OptionId { + + @Override + public String id() { + return "featureName"; //$NON-NLS-1$ + } + +} diff --git a/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/features/FeatureProviderOptionId.java b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/features/FeatureProviderOptionId.java new file mode 100644 index 000000000..53251fcf0 --- /dev/null +++ b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/features/FeatureProviderOptionId.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.ldc.internal.pde.core.templates.features; + +import org.eclipse.passage.ldc.internal.pde.core.templates.OptionId; + +public final class FeatureProviderOptionId implements OptionId { + + @Override + public String id() { + return "featureProvider"; //$NON-NLS-1$ + } + +} diff --git a/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/features/FeatureVersionVersionOptionId.java b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/features/FeatureVersionVersionOptionId.java new file mode 100644 index 000000000..ea531f524 --- /dev/null +++ b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/features/FeatureVersionVersionOptionId.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.ldc.internal.pde.core.templates.features; + +import org.eclipse.passage.ldc.internal.pde.core.templates.OptionId; + +public final class FeatureVersionVersionOptionId implements OptionId { + + @Override + public String id() { + return "featureVersionVersion"; //$NON-NLS-1$ + } + +} diff --git a/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/products/ProductIdentifierOptionId.java b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/products/ProductIdentifierOptionId.java new file mode 100644 index 000000000..6b7d9f30e --- /dev/null +++ b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/products/ProductIdentifierOptionId.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.ldc.internal.pde.core.templates.products; + +import org.eclipse.passage.ldc.internal.pde.core.templates.OptionId; + +public final class ProductIdentifierOptionId implements OptionId { + + @Override + public String id() { + return "productIdentifier"; //$NON-NLS-1$ + } + +} diff --git a/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/products/ProductNameOptionId.java b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/products/ProductNameOptionId.java new file mode 100644 index 000000000..aa355e1a3 --- /dev/null +++ b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/products/ProductNameOptionId.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.ldc.internal.pde.core.templates.products; + +import org.eclipse.passage.ldc.internal.pde.core.templates.OptionId; + +public final class ProductNameOptionId implements OptionId { + + @Override + public String id() { + return "productName"; //$NON-NLS-1$ + } + +} diff --git a/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/products/ProductVersionVersionOptionId.java b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/products/ProductVersionVersionOptionId.java new file mode 100644 index 000000000..253b37223 --- /dev/null +++ b/bundles/org.eclipse.passage.ldc.pde.core.templates/src/org/eclipse/passage/ldc/internal/pde/core/templates/products/ProductVersionVersionOptionId.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.ldc.internal.pde.core.templates.products; + +import org.eclipse.passage.ldc.internal.pde.core.templates.OptionId; + +public final class ProductVersionVersionOptionId implements OptionId { + + @Override + public String id() { + return "productVersionVersion"; //$NON-NLS-1$ + } + +} diff --git a/bundles/org.eclipse.passage.ldc.pde.core.templates/templates/dev_minimal/features/$featureIdentifier$.features_xmi b/bundles/org.eclipse.passage.ldc.pde.core.templates/templates/dev_minimal/features/$featureIdentifier$.features_xmi new file mode 100644 index 000000000..72bc06c4e --- /dev/null +++ b/bundles/org.eclipse.passage.ldc.pde.core.templates/templates/dev_minimal/features/$featureIdentifier$.features_xmi @@ -0,0 +1,6 @@ + + + + + + diff --git a/bundles/org.eclipse.passage.ldc.pde.core.templates/templates/dev_minimal/products/$productIdentifier$.products_xmi b/bundles/org.eclipse.passage.ldc.pde.core.templates/templates/dev_minimal/products/$productIdentifier$.products_xmi new file mode 100644 index 000000000..d1d87f87d --- /dev/null +++ b/bundles/org.eclipse.passage.ldc.pde.core.templates/templates/dev_minimal/products/$productIdentifier$.products_xmi @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/BaseLicensedTemplateSection.java b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/BaseLicensedProductSection.java similarity index 70% rename from bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/BaseLicensedTemplateSection.java rename to bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/BaseLicensedProductSection.java index 0d14a6d04..8e0b3ae02 100644 --- a/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/BaseLicensedTemplateSection.java +++ b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/BaseLicensedProductSection.java @@ -12,93 +12,94 @@ *******************************************************************************/ package org.eclipse.passage.ldc.internal.pde.ui.templates; -import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Locale; -import java.util.ResourceBundle; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.passage.ldc.internal.pde.core.templates.DefaultProductRequirement; +import org.eclipse.passage.ldc.internal.pde.core.templates.TemplateId; +import org.eclipse.passage.ldc.internal.pde.core.templates.features.FeatureIdentifierOptionId; +import org.eclipse.passage.ldc.internal.pde.core.templates.features.FeatureNameOptionId; +import org.eclipse.passage.ldc.internal.pde.core.templates.features.FeatureProviderOptionId; +import org.eclipse.passage.ldc.internal.pde.core.templates.features.FeatureVersionVersionOptionId; +import org.eclipse.passage.ldc.internal.pde.core.templates.products.ProductIdentifierOptionId; +import org.eclipse.passage.ldc.internal.pde.core.templates.products.ProductNameOptionId; +import org.eclipse.passage.ldc.internal.pde.core.templates.products.ProductVersionVersionOptionId; import org.eclipse.passage.lic.internal.api.requirements.Requirement; import org.eclipse.passage.lic.internal.equinox.requirements.RequirementsToBundle; import org.eclipse.pde.core.plugin.IMatchRules; import org.eclipse.pde.core.plugin.IPluginBase; import org.eclipse.pde.core.plugin.IPluginElement; import org.eclipse.pde.core.plugin.IPluginExtension; +import org.eclipse.pde.core.plugin.IPluginModelBase; import org.eclipse.pde.core.plugin.IPluginReference; import org.eclipse.pde.core.plugin.ISharedPluginModel; import org.eclipse.pde.internal.core.ibundle.IBundlePluginBase; import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase; -import org.eclipse.pde.ui.templates.OptionTemplateSection; +import org.eclipse.pde.ui.IFieldData; import org.eclipse.pde.ui.templates.PluginReference; import org.osgi.framework.Bundle; import org.osgi.framework.Constants; import org.osgi.framework.FrameworkUtil; @SuppressWarnings("restriction") -public abstract class BaseLicensedTemplateSection extends OptionTemplateSection { +public abstract class BaseLicensedProductSection extends BaseLicensingSection { public static final String KEY_APPLICATION_CLASS = "applicationClass"; //$NON-NLS-1$ public static final String KEY_WINDOW_TITLE = "windowTitle"; //$NON-NLS-1$ - public static final String KEY_PRODUCT_BRANDING = "productBranding"; //$NON-NLS-1$ - public static final String KEY_PRODUCT_NAME = "productName"; //$NON-NLS-1$ public static final String VALUE_PRODUCT_ID = "product"; //$NON-NLS-1$ - public static final String VALUE_PRODUCT_NAME = "Licensed Product"; //$NON-NLS-1$ public static final String VALUE_PERSPECTIVE_NAME = "Licensed Perspective"; //$NON-NLS-1$ public static final String VALUE_APPLICATION_ID = "application"; //$NON-NLS-1$ protected static final String VALUE_PROCESSOR_LICENSING_ID = "licensing"; //$NON-NLS-1$ protected static final String VALUE_PROCESSOR_LICENSING_CLASS = "org.eclipse.passage.lic.internal.e4.ui.addons.E4LicensingProcessor"; //$NON-NLS-1$ - private Bundle bundle = FrameworkUtil.getBundle(BaseLicensedTemplateSection.class); + public BaseLicensedProductSection() { + super(BaseLicensedProductSection.class); + } - @Override - public boolean isDependentOnParentWizard() { - return true; + public BaseLicensedProductSection(Class clazz) { + super(FrameworkUtil.getBundle(clazz)); } - @Override - public String getUsedExtensionPoint() { - return null; + public BaseLicensedProductSection(Bundle bundle) { + super(bundle); } @Override - public String[] getNewFiles() { - return new String[0]; + public boolean isDependentOnParentWizard() { + return true; } @Override - protected URL getInstallURL() { - return bundle.getEntry("/"); //$NON-NLS-1$ + protected String getTemplateDirectory() { + return "templates"; //$NON-NLS-1$ } + protected abstract TemplateId getDevTemplate(); + @Override - protected ResourceBundle getPluginResourceBundle() { - return Platform.getResourceBundle(bundle); + protected void initializeFields(IFieldData data) { + // In a new project wizard, we don't know this yet - the + // model has not been created + String packageName = getFormattedPackageName(data.getId()); + initializeOption(KEY_PACKAGE_NAME, packageName); } @Override - protected String getTemplateDirectory() { - return "templates"; //$NON-NLS-1$ + public void initializeFields(IPluginModelBase modelBase) { + initializeProductDev(modelBase); + String packageName = getFormattedPackageName(modelBase.getPluginBase().getId()); + initializeOption(KEY_PACKAGE_NAME, packageName); } - protected String getFormattedPackageName(String id) { - StringBuilder buffer = new StringBuilder(); - for (int i = 0; i < id.length(); i++) { - char ch = id.charAt(i); - if (buffer.length() == 0) { - if (Character.isJavaIdentifierStart(ch)) - buffer.append(Character.toLowerCase(ch)); - } else { - if (Character.isJavaIdentifierPart(ch) || ch == '.') - buffer.append(ch); - } - } - return buffer.toString().toLowerCase(Locale.ENGLISH); + @Override + protected void generateFiles(IProgressMonitor monitor) throws CoreException { + super.generateFiles(monitor); + generateFiles(monitor, bundleTemplate(getDevTemplate())); } protected IPluginReference[] getDependencies(List symbolicNames) { @@ -128,19 +129,15 @@ protected void createLicensingCapability(String identifier) { protected void createApplicationExtension(String identifier, String classValue) throws CoreException { IPluginBase plugin = model.getPluginBase(); - IPluginExtension extension = createExtension("org.eclipse.core.runtime.applications", true); //$NON-NLS-1$ extension.setId(identifier); - IPluginElement element = model.getPluginFactory().createElement(extension); element.setName("application"); //$NON-NLS-1$ extension.add(element); - IPluginElement run = model.getPluginFactory().createElement(element); run.setName("run"); //$NON-NLS-1$ run.setAttribute("class", classValue); //$NON-NLS-1$ element.add(run); - if (!extension.isInTheModel()) { plugin.add(extension); } @@ -201,4 +198,14 @@ protected Requirement createProductRequirement(String product) { ).get(); } + protected void initializeProductDev(IPluginModelBase base) { + systemOption(new FeatureIdentifierOptionId(), base.getPluginBase().getId() + '.' + VALUE_PRODUCT_ID); + systemOption(new FeatureNameOptionId(), base.getPluginBase().getName()); + systemOption(new FeatureProviderOptionId(), base.getPluginBase().getProviderName()); + systemOption(new FeatureVersionVersionOptionId(), base.getPluginBase().getVersion()); + systemOption(new ProductIdentifierOptionId(), base.getPluginBase().getId() + '.' + VALUE_PRODUCT_ID); + systemOption(new ProductNameOptionId(), base.getPluginBase().getName()); + systemOption(new ProductVersionVersionOptionId(), base.getPluginBase().getVersion()); + } + } diff --git a/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/BaseLicensingSection.java b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/BaseLicensingSection.java new file mode 100644 index 000000000..06ca49933 --- /dev/null +++ b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/BaseLicensingSection.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.ldc.internal.pde.ui.templates; + +import java.net.URL; +import java.util.Locale; +import java.util.ResourceBundle; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.passage.ldc.internal.pde.core.templates.OptionId; +import org.eclipse.passage.ldc.internal.pde.core.templates.TemplateId; +import org.eclipse.pde.ui.templates.OptionTemplateSection; +import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; + +public abstract class BaseLicensingSection extends OptionTemplateSection { + + private final Bundle bundle; + + public BaseLicensingSection() { + this(BaseLicensingSection.class); + } + + public BaseLicensingSection(Class clazz) { + this(FrameworkUtil.getBundle(clazz)); + } + + public BaseLicensingSection(Bundle bundle) { + this.bundle = bundle; + } + + @Override + public String getUsedExtensionPoint() { + // none at the moment + return null; + } + + @Override + protected URL getInstallURL() { + return bundle.getEntry("/"); //$NON-NLS-1$ + } + + @Override + protected ResourceBundle getPluginResourceBundle() { + return Platform.getResourceBundle(bundle); + } + + @Override + protected void updateModel(IProgressMonitor monitor) throws CoreException { + // nothing to do ATM, but perharps capability declaration should be moved here + } + + // FIXME:AF: extract to function + protected String getFormattedPackageName(String id) { + StringBuilder buffer = new StringBuilder(); + for (int i = 0; i < id.length(); i++) { + char ch = id.charAt(i); + if (buffer.length() == 0) { + if (Character.isJavaIdentifierStart(ch)) + buffer.append(Character.toLowerCase(ch)); + } else { + if (Character.isJavaIdentifierPart(ch) || ch == '.') + buffer.append(ch); + } + } + return buffer.toString().toLowerCase(Locale.ENGLISH); + } + + protected URL bundleTemplate(TemplateId id) { + return FileLocator.find(FrameworkUtil.getBundle(id.getClass()), // + Path.ROOT.append(getTemplateDirectory()).append(id.id())); + } + + protected void systemOption(OptionId id, String value) { + addOption(id.id(), id.id(), value, 0); + } + +} diff --git a/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e3/LicensedE3ProductContentWizard.java b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e3/LicensedE3ProductContentWizard.java index a6abcd72a..97d1c5cbf 100644 --- a/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e3/LicensedE3ProductContentWizard.java +++ b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e3/LicensedE3ProductContentWizard.java @@ -19,7 +19,8 @@ public class LicensedE3ProductContentWizard extends NewPluginTemplateWizard { @Override public ITemplateSection[] createTemplateSections() { - return new ITemplateSection[] { new LicensedE3ProductTemplateSection() }; + return new ITemplateSection[] { // + new LicensedE3ProductTemplateSection(), // + }; } - } diff --git a/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e3/LicensedE3ProductTemplateSection.java b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e3/LicensedE3ProductTemplateSection.java index 6b38d27c4..514dc0449 100644 --- a/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e3/LicensedE3ProductTemplateSection.java +++ b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e3/LicensedE3ProductTemplateSection.java @@ -19,19 +19,20 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.passage.ldc.internal.pde.ui.templates.BaseLicensedTemplateSection; +import org.eclipse.passage.ldc.internal.pde.core.templates.TemplateId; +import org.eclipse.passage.ldc.internal.pde.core.templates.dev.DevMinimalTemplateId; +import org.eclipse.passage.ldc.internal.pde.core.templates.products.ProductIdentifierOptionId; +import org.eclipse.passage.ldc.internal.pde.ui.templates.BaseLicensedProductSection; import org.eclipse.passage.ldc.internal.pde.ui.templates.HelpContexts; import org.eclipse.passage.ldc.internal.pde.ui.templates.i18n.PdeUiTemplatesMessages; import org.eclipse.passage.lic.internal.api.requirements.Requirement; import org.eclipse.pde.core.plugin.IPluginBase; import org.eclipse.pde.core.plugin.IPluginElement; import org.eclipse.pde.core.plugin.IPluginExtension; -import org.eclipse.pde.core.plugin.IPluginModelBase; import org.eclipse.pde.core.plugin.IPluginReference; -import org.eclipse.pde.ui.IFieldData; @SuppressWarnings("restriction") -public class LicensedE3ProductTemplateSection extends BaseLicensedTemplateSection { +public class LicensedE3ProductTemplateSection extends BaseLicensedProductSection { private static final String LICENSED_E3_PRODUCT = "LicensedE3Product"; //$NON-NLS-1$ @@ -60,29 +61,19 @@ private void createOptions() { } @Override - protected void initializeFields(IFieldData data) { - // In a new project wizard, we don't know this yet - the - // model has not been created - String packageName = getFormattedPackageName(data.getId()); - initializeOption(KEY_PACKAGE_NAME, packageName); - } - - @Override - public void initializeFields(IPluginModelBase modelBase) { - String packageName = getFormattedPackageName(modelBase.getPluginBase().getId()); - initializeOption(KEY_PACKAGE_NAME, packageName); + public String getSectionId() { + return LICENSED_E3_PRODUCT; } @Override - public String getSectionId() { - return LICENSED_E3_PRODUCT; + protected TemplateId getDevTemplate() { + return new DevMinimalTemplateId(); } @Override protected void updateModel(IProgressMonitor monitor) throws CoreException { setManifestHeader("Bundle-ActivationPolicy", "lazy"); //$NON-NLS-1$ //$NON-NLS-2$ - String productFqn = model.getPluginBase().getId() + '.' + VALUE_PRODUCT_ID; - createLicensingCapability(productFqn); + createLicensingCapability(getStringOption(new ProductIdentifierOptionId().id())); String classValue = getStringOption(KEY_PACKAGE_NAME) + '.' + getStringOption(KEY_APPLICATION_CLASS); createApplicationExtension(VALUE_APPLICATION_ID, classValue); createPerspectiveExtension(); @@ -133,4 +124,9 @@ public IPluginReference[] getDependencies(String schemaVersion) { return getDependencies(getRCP3xDependencies()); } + @Override + public String[] getNewFiles() { + return new String[0]; + } + } diff --git a/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e4/LicensedE4ProductContentWizard.java b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e4/LicensedE4ProductContentWizard.java index 32b396df0..5811f8e21 100644 --- a/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e4/LicensedE4ProductContentWizard.java +++ b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e4/LicensedE4ProductContentWizard.java @@ -20,7 +20,8 @@ public class LicensedE4ProductContentWizard extends NewPluginTemplateWizard { @Override public ITemplateSection[] createTemplateSections() { - return new ITemplateSection[] { new LicensedE4ProductTemplateSection() }; + return new ITemplateSection[] { // + new LicensedE4ProductTemplateSection(), // + }; } - } diff --git a/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e4/LicensedE4ProductTemplateSection.java b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e4/LicensedE4ProductTemplateSection.java index a0f65a3b6..0ce0b879a 100644 --- a/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e4/LicensedE4ProductTemplateSection.java +++ b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/e4/LicensedE4ProductTemplateSection.java @@ -19,20 +19,21 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.passage.ldc.internal.pde.ui.templates.BaseLicensedTemplateSection; +import org.eclipse.passage.ldc.internal.pde.core.templates.TemplateId; +import org.eclipse.passage.ldc.internal.pde.core.templates.dev.DevMinimalTemplateId; +import org.eclipse.passage.ldc.internal.pde.core.templates.products.ProductIdentifierOptionId; +import org.eclipse.passage.ldc.internal.pde.ui.templates.BaseLicensedProductSection; import org.eclipse.passage.ldc.internal.pde.ui.templates.HelpContexts; import org.eclipse.passage.ldc.internal.pde.ui.templates.i18n.PdeUiTemplatesMessages; import org.eclipse.passage.lic.internal.api.requirements.Requirement; import org.eclipse.pde.core.plugin.IPluginBase; import org.eclipse.pde.core.plugin.IPluginElement; import org.eclipse.pde.core.plugin.IPluginExtension; -import org.eclipse.pde.core.plugin.IPluginModelBase; import org.eclipse.pde.core.plugin.IPluginReference; -import org.eclipse.pde.ui.IFieldData; @SuppressWarnings("restriction") @Deprecated -public class LicensedE4ProductTemplateSection extends BaseLicensedTemplateSection { +public class LicensedE4ProductTemplateSection extends BaseLicensedProductSection { private static final String LICENSED_E4_PRODUCT = "LicensedE4Product"; //$NON-NLS-1$ private static final String E4_SWT_APPLICATION_ID = "org.eclipse.e4.ui.workbench.swt.E4Application"; //$NON-NLS-1$ @@ -59,29 +60,19 @@ private void createOptions() { } @Override - protected void initializeFields(IFieldData data) { - // In a new project wizard, we don't know this yet - the - // model has not been created - String packageName = getFormattedPackageName(data.getId()); - initializeOption(KEY_PACKAGE_NAME, packageName); - } - - @Override - public void initializeFields(IPluginModelBase modelBase) { - String packageName = getFormattedPackageName(modelBase.getPluginBase().getId()); - initializeOption(KEY_PACKAGE_NAME, packageName); + public String getSectionId() { + return LICENSED_E4_PRODUCT; } @Override - public String getSectionId() { - return LICENSED_E4_PRODUCT; + protected TemplateId getDevTemplate() { + return new DevMinimalTemplateId(); } @Override protected void updateModel(IProgressMonitor monitor) throws CoreException { setManifestHeader("Bundle-ActivationPolicy", "lazy"); //$NON-NLS-1$ //$NON-NLS-2$ - String productFqn = model.getPluginBase().getId() + '.' + VALUE_PRODUCT_ID; - createLicensingCapability(productFqn); + createLicensingCapability(getStringOption(new ProductIdentifierOptionId().id())); createProductExtension(); } diff --git a/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/fullfeather/LicensedE4FullFeatherProductContentWizard.java b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/fullfeather/LicensedE4FullFeatherProductContentWizard.java index 537c554c3..d635b0b39 100644 --- a/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/fullfeather/LicensedE4FullFeatherProductContentWizard.java +++ b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/fullfeather/LicensedE4FullFeatherProductContentWizard.java @@ -19,7 +19,8 @@ public final class LicensedE4FullFeatherProductContentWizard extends NewPluginTe @Override public ITemplateSection[] createTemplateSections() { - return new ITemplateSection[] { new LicensedE4FullFeatherProductTemplateSection() }; + return new ITemplateSection[] { // + new LicensedE4FullFeatherProductTemplateSection(), // + }; } - } diff --git a/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/fullfeather/LicensedE4FullFeatherProductTemplateSection.java b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/fullfeather/LicensedE4FullFeatherProductTemplateSection.java index 3268cde8c..e93dd04d9 100644 --- a/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/fullfeather/LicensedE4FullFeatherProductTemplateSection.java +++ b/bundles/org.eclipse.passage.ldc.pde.ui.templates/src/org/eclipse/passage/ldc/internal/pde/ui/templates/fullfeather/LicensedE4FullFeatherProductTemplateSection.java @@ -20,19 +20,20 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.passage.ldc.internal.pde.ui.templates.BaseLicensedTemplateSection; +import org.eclipse.passage.ldc.internal.pde.core.templates.TemplateId; +import org.eclipse.passage.ldc.internal.pde.core.templates.dev.DevMinimalTemplateId; +import org.eclipse.passage.ldc.internal.pde.core.templates.products.ProductIdentifierOptionId; +import org.eclipse.passage.ldc.internal.pde.ui.templates.BaseLicensedProductSection; import org.eclipse.passage.ldc.internal.pde.ui.templates.HelpContexts; import org.eclipse.passage.ldc.internal.pde.ui.templates.i18n.PdeUiTemplatesMessages; import org.eclipse.passage.lic.internal.api.requirements.Requirement; import org.eclipse.pde.core.plugin.IPluginBase; import org.eclipse.pde.core.plugin.IPluginElement; import org.eclipse.pde.core.plugin.IPluginExtension; -import org.eclipse.pde.core.plugin.IPluginModelBase; import org.eclipse.pde.core.plugin.IPluginReference; -import org.eclipse.pde.ui.IFieldData; @SuppressWarnings("restriction") -public final class LicensedE4FullFeatherProductTemplateSection extends BaseLicensedTemplateSection { +public final class LicensedE4FullFeatherProductTemplateSection extends BaseLicensedProductSection { public LicensedE4FullFeatherProductTemplateSection() { setPageCount(1); @@ -49,30 +50,20 @@ public void addPages(Wizard wizard) { } @Override - protected void initializeFields(IFieldData data) { - // In a new project wizard, we don't know this yet - the - // model has not been created - String packageName = getFormattedPackageName(data.getId()); - initializeOption(KEY_PACKAGE_NAME, packageName); - } - - @Override - public void initializeFields(IPluginModelBase modelBase) { - String packageName = getFormattedPackageName(modelBase.getPluginBase().getId()); - initializeOption(KEY_PACKAGE_NAME, packageName); + public String getSectionId() { + return "LicensedE4FullFeatherProduct"; //$NON-NLS-1$ } @Override - public String getSectionId() { - return "LicensedE4FullFeatherProduct"; //$NON-NLS-1$ + protected TemplateId getDevTemplate() { + return new DevMinimalTemplateId(); } @Override protected void updateModel(IProgressMonitor monitor) throws CoreException { setManifestHeader("Bundle-ActivationPolicy", "lazy"); //$NON-NLS-1$ //$NON-NLS-2$ setManifestHeader("Service-Component", "OSGI-INF/*"); //$NON-NLS-1$ //$NON-NLS-2$ - String productFqn = model.getPluginBase().getId() + '.' + VALUE_PRODUCT_ID; - createLicensingCapability(productFqn); + createLicensingCapability(getStringOption(new ProductIdentifierOptionId().id())); createProductExtension(); }