├── .gitignore ├── README.md ├── issue_template.md ├── carbon-feature-plugin ├── src │ └── main │ │ ├── java │ │ └── org │ │ │ └── wso2 │ │ │ └── maven │ │ │ └── p2 │ │ │ ├── repository │ │ │ ├── Bundle.java │ │ │ ├── Feature.java │ │ │ ├── CatFeature.java │ │ │ ├── Category.java │ │ │ ├── RepositoryGeneratorMojo.java │ │ │ └── RepositoryResourceBundle.java │ │ │ ├── exceptions │ │ │ ├── CarbonArtifactNotFoundException.java │ │ │ └── MissingRequiredPropertyException.java │ │ │ ├── beans │ │ │ ├── product │ │ │ │ ├── ConfigIni.java │ │ │ │ ├── Launcher.java │ │ │ │ ├── config │ │ │ │ │ ├── ProductFileConfig.java │ │ │ │ │ └── ProductConfig.java │ │ │ │ ├── Property.java │ │ │ │ ├── Configurations.java │ │ │ │ ├── Product.java │ │ │ │ └── Plugin.java │ │ │ └── CarbonArtifact.java │ │ │ ├── feature │ │ │ ├── generate │ │ │ │ ├── Bundle.java │ │ │ │ ├── Advice.java │ │ │ │ ├── Feature.java │ │ │ │ └── FeatureGeneratorMojo.java │ │ │ ├── uninstall │ │ │ │ ├── Feature.java │ │ │ │ ├── FeatureUnInstallMojo.java │ │ │ │ └── FeatureUnInstaller.java │ │ │ └── install │ │ │ │ ├── Feature.java │ │ │ │ ├── FeatureInstallMojo.java │ │ │ │ ├── FeatureInstallResourceBundle.java │ │ │ │ └── FeatureInstaller.java │ │ │ ├── utils │ │ │ ├── PropertyReplacer.java │ │ │ ├── MavenUtils.java │ │ │ ├── P2Constants.java │ │ │ ├── StandaloneManager.java │ │ │ ├── DependencyResolver.java │ │ │ ├── BundleUtils.java │ │ │ ├── ProductFileUtils.java │ │ │ ├── P2Utils.java │ │ │ ├── P2ApplicationLaunchManager.java │ │ │ └── FileManagementUtil.java │ │ │ ├── product │ │ │ └── PublishProductMojo.java │ │ │ └── profile │ │ │ └── GenerateProfileMojo.java │ │ └── resources │ │ └── META-INF │ │ └── plexus │ │ └── components.xml ├── pom.xml └── LICENSE ├── pull_request_template.md ├── pom.xml └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | target 3 | .classpath 4 | .settings 5 | .project 6 | *.iml 7 | *.iws 8 | *.ipr 9 | .idea 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #WSO2 Carbon Maven Plugins 2 | 3 | This repository provides supplementary maven plugins for WSO2 carbon developers. 4 | 5 | Follow the link below for details of plugins: 6 | 7 | * [Carbon Feature Plugin](docs/CarbonFeaturePlugin.md) 8 | 9 | # How to Contribute 10 | * Please report issues at [Issues](https://github.com/wso2/carbon-maven-plugins/issues). 11 | * Send your pull requests to [master branch](https://github.com/wso2/carbon-maven-plugins/tree/master) 12 | 13 | #Contact us 14 | WSO2 developers can be contacted via the mailing lists: 15 | * WSO2 Developers List : dev@wso2.org 16 | * WSO2 Architecture List : architecture@wso2.org -------------------------------------------------------------------------------- /issue_template.md: -------------------------------------------------------------------------------- 1 | **Description:** 2 | 3 | 4 | **Suggested Labels:** 5 | 6 | 7 | **Suggested Assignees:** 8 | 9 | 10 | **Affected Product Version:** 11 | 12 | **OS, DB, other environment details and versions:** 13 | 14 | **Steps to reproduce:** 15 | 16 | 17 | **Related Issues:** 18 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/repository/Bundle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.repository; 18 | 19 | import org.wso2.maven.p2.beans.CarbonArtifact; 20 | 21 | /** 22 | * Bean class representing a Bundle object provided as an input param to RepositoryGeneratorMojo. 23 | * 24 | * @since 2.0.0 25 | */ 26 | public class Bundle extends CarbonArtifact { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/exceptions/CarbonArtifactNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.exceptions; 18 | 19 | /** 20 | * CarbonArtifactNotFoundException is thrown when a CarbonArtifact is not found. 21 | * 22 | * @since 2.0.0 23 | */ 24 | public class CarbonArtifactNotFoundException extends Exception { 25 | 26 | /** 27 | * Constructs the CarbonArtifactNotFoundException. 28 | * 29 | * @param message message of the exception. 30 | */ 31 | public CarbonArtifactNotFoundException(String message) { 32 | super(message); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/exceptions/MissingRequiredPropertyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.exceptions; 18 | 19 | /** 20 | * MissingRequiredPropertyException is thrown if required property keys are missing when generating a carbon feature. 21 | * 22 | * @since 2.0.0 23 | */ 24 | public class MissingRequiredPropertyException extends Exception { 25 | 26 | /** 27 | * Constructs the MissingRequiredPropertyException. 28 | * 29 | * @param message message of the exception. 30 | */ 31 | public MissingRequiredPropertyException(String message) { 32 | super(message); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/repository/Feature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.repository; 18 | 19 | import org.wso2.maven.p2.beans.CarbonArtifact; 20 | 21 | /** 22 | * Bean class representing a Feature object provided as an input param to RepositoryGeneratorMojo. 23 | * 24 | * @since 2.0.0 25 | */ 26 | public class Feature extends CarbonArtifact { 27 | private String id; 28 | 29 | /** 30 | * Returns the feature id represented by this feature. 31 | * 32 | * @return String feature id 33 | */ 34 | public String getId() { 35 | return id; 36 | } 37 | 38 | /** 39 | * Sets the feture id represented by this feature. 40 | * 41 | * @param id String 42 | */ 43 | public void setId(String id) { 44 | this.id = id; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/beans/product/ConfigIni.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.beans.product; 18 | 19 | import org.wso2.maven.p2.utils.P2Constants; 20 | 21 | import javax.xml.bind.annotation.XmlAttribute; 22 | import javax.xml.bind.annotation.XmlRootElement; 23 | 24 | /** 25 | * Bean to represent configInit data. 26 | * 27 | * This is used to 28 | * [1] Capture build-time configInit data from distribution pom file. 29 | * [2] Write configIni data to carbon.product file. 30 | * 31 | * @since 3.1.0 32 | */ 33 | @XmlRootElement 34 | public class ConfigIni { 35 | 36 | private String use = P2Constants.ProductFile.Product.CONFIG_INI_USE; 37 | 38 | public String getUse() { 39 | return use; 40 | } 41 | 42 | @XmlAttribute 43 | public void setUse(String use) { 44 | this.use = use; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/beans/product/Launcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.beans.product; 18 | 19 | import org.wso2.maven.p2.utils.P2Constants.ProductFile.Product; 20 | 21 | import javax.xml.bind.annotation.XmlAttribute; 22 | import javax.xml.bind.annotation.XmlRootElement; 23 | 24 | /** 25 | * Bean to represent launcher data. 26 | * 27 | * This is used to 28 | * [1] Capture build-time product file launcher data from distribution pom file. 29 | * [2] Write launcher data to carbon.product file. 30 | * 31 | * @since 3.1.0 32 | */ 33 | @XmlRootElement 34 | public class Launcher { 35 | 36 | private String name = Product.LAUNCHER_NAME; 37 | 38 | public String getName() { 39 | return name; 40 | } 41 | 42 | @XmlAttribute 43 | public void setName(String name) { 44 | this.name = name; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/feature/generate/Bundle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.feature.generate; 18 | 19 | import org.wso2.maven.p2.beans.CarbonArtifact; 20 | import org.wso2.maven.p2.utils.BundleUtils; 21 | 22 | /** 23 | * Bean class representing a Bundle object provided as an input param to FeatureGenMojo. 24 | * 25 | * @since 2.0.0 26 | */ 27 | public class Bundle extends CarbonArtifact { 28 | /** 29 | * Returns the OSGi content in a string format. 30 | *

31 | * {symbolic name} : {bundle version} 32 | *

33 | * 34 | * @return String 35 | */ 36 | public String toOSGIString() { 37 | return getSymbolicName() + ":" + getBundleVersion(); 38 | } 39 | 40 | /** 41 | * Returns the OSGi version of the bundle. 42 | * 43 | * @return String 44 | */ 45 | public String getOSGIVersion() { 46 | return BundleUtils.getOSGIVersion(super.getVersion()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/beans/product/config/ProductFileConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.beans.product.config; 18 | 19 | import org.wso2.maven.p2.utils.P2Constants; 20 | 21 | /** 22 | * Bean to represent build-time product file configurations. 23 | * 24 | * This is used to capture build-time product file configuration 25 | * data from distribution pom file. 26 | * 27 | * @since 3.1.0 28 | */ 29 | public class ProductFileConfig { 30 | 31 | private Float pdeVersion = P2Constants.ProductFile.PDE_VERSION; 32 | private ProductConfig productConfig = new ProductConfig(); 33 | 34 | public Float getPdeVersion() { 35 | return pdeVersion; 36 | } 37 | 38 | @SuppressWarnings("unused") 39 | public void setPdeVersion(Float pdeVersion) { 40 | this.pdeVersion = pdeVersion; 41 | } 42 | 43 | public ProductConfig getProductConfig() { 44 | return productConfig; 45 | } 46 | 47 | @SuppressWarnings("unused") 48 | public void setProductConfig(ProductConfig productConfig) { 49 | this.productConfig = productConfig; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/feature/generate/Advice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.feature.generate; 18 | 19 | /** 20 | * Bean class to represent an AdviceFile Entry. 21 | * 22 | * @since 2.0.0 23 | */ 24 | public class Advice { 25 | private String name; 26 | private String value; 27 | 28 | /** 29 | * Returns the name of the AdviceFile key. 30 | * 31 | * @return String AdviceFile key 32 | */ 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | /** 38 | * Returns the value for a give AdviceFile key. 39 | * 40 | * @return String value for a key 41 | */ 42 | public String getValue() { 43 | return value; 44 | } 45 | 46 | /** 47 | * Sets the name of the AdviceFile key. 48 | * 49 | * @param name String 50 | */ 51 | public void setName(String name) { 52 | this.name = name; 53 | } 54 | 55 | /** 56 | * Sets the value for a give AdviceFile key. 57 | * 58 | * @param value String 59 | */ 60 | public void setValue(String value) { 61 | this.value = value; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/beans/product/Property.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.beans.product; 18 | 19 | import javax.xml.bind.annotation.XmlAttribute; 20 | import javax.xml.bind.annotation.XmlRootElement; 21 | 22 | /** 23 | * Bean to represent a property. 24 | * 25 | * This is used to 26 | * [1] Capture build-time product file property data from distribution pom file. 27 | * [2] Write property data to carbon.product file. 28 | * 29 | * @since 3.1.0 30 | */ 31 | @XmlRootElement 32 | public class Property { 33 | 34 | private String name; 35 | private Boolean value; 36 | 37 | @SuppressWarnings("unused") 38 | public Property() {} 39 | 40 | public Property(String name, Boolean value) { 41 | this.setName(name); 42 | this.setValue(value); 43 | } 44 | 45 | public String getName() { 46 | return name; 47 | } 48 | 49 | @XmlAttribute 50 | public void setName(String name) { 51 | this.name = name; 52 | } 53 | 54 | public Boolean getValue() { 55 | return value; 56 | } 57 | 58 | @XmlAttribute 59 | public void setValue(Boolean value) { 60 | this.value = value; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/feature/uninstall/Feature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.feature.uninstall; 18 | 19 | /** 20 | * Bean class representing a Feature object provided as an input param to FeatureGenMojo. 21 | * 22 | * @since 2.0.0 23 | */ 24 | public class Feature { 25 | private String id; 26 | private String version; 27 | 28 | /** 29 | * Gets the id of the feature to be uninstalled. 30 | * 31 | * @return String 32 | */ 33 | public String getId() { 34 | return id; 35 | } 36 | 37 | /** 38 | * Sets the id of the feature to be uninstalled. 39 | * 40 | * @param id String 41 | */ 42 | public void setId(String id) { 43 | this.id = id; 44 | } 45 | 46 | /** 47 | * Gets the version of the feature to be uninstalled. 48 | * 49 | * @return String 50 | */ 51 | public String getVersion() { 52 | return version; 53 | } 54 | 55 | /** 56 | * Sets the version of the feature to be uninstalled. 57 | * 58 | * @param version String 59 | */ 60 | public void setVersion(String version) { 61 | this.version = version; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/beans/product/Configurations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.beans.product; 18 | 19 | import java.util.List; 20 | import javax.xml.bind.annotation.XmlElement; 21 | import javax.xml.bind.annotation.XmlRootElement; 22 | 23 | /** 24 | * Bean to represent configurations. 25 | * 26 | * This is used write configurations data to carbon.product file. 27 | * 28 | * @since 3.1.0 29 | */ 30 | @XmlRootElement 31 | public class Configurations { 32 | 33 | private List plugins; 34 | private List properties; 35 | 36 | @SuppressWarnings("unused") 37 | public Configurations() {} 38 | 39 | public Configurations(List plugin, List property) { 40 | this.setPlugins(plugin); 41 | this.setProperties(property); 42 | } 43 | 44 | public List getPlugins() { 45 | return plugins; 46 | } 47 | 48 | @XmlElement(name = "plugin") 49 | public void setPlugins(List plugins) { 50 | this.plugins = plugins; 51 | } 52 | 53 | public List getProperties() { 54 | return properties; 55 | } 56 | 57 | @XmlElement(name = "property") 58 | public void setProperties(List properties) { 59 | this.properties = properties; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/beans/product/Product.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.beans.product; 18 | 19 | import org.wso2.maven.p2.beans.product.config.ProductConfig; 20 | import org.wso2.maven.p2.utils.P2Constants; 21 | 22 | import javax.xml.bind.annotation.XmlAttribute; 23 | import javax.xml.bind.annotation.XmlElement; 24 | import javax.xml.bind.annotation.XmlRootElement; 25 | 26 | /** 27 | * Bean to represent a product. 28 | * 29 | * This is used to write product data to carbon.product file. 30 | * 31 | * @since 3.1.0 32 | */ 33 | @XmlRootElement 34 | public class Product extends ProductConfig { 35 | 36 | private Boolean useFeatures = P2Constants.ProductFile.Product.USE_FEATURES; 37 | private Configurations configurations; 38 | 39 | @SuppressWarnings("unused") 40 | public Boolean getUseFeatures() { 41 | return useFeatures; 42 | } 43 | 44 | @XmlAttribute 45 | @SuppressWarnings("unused") 46 | public void setUseFeatures(Boolean useFeatures) { 47 | this.useFeatures = useFeatures; 48 | } 49 | 50 | @SuppressWarnings("unused") 51 | public Configurations getConfigurations() { 52 | return configurations; 53 | } 54 | 55 | @XmlElement 56 | public void setConfigurations(Configurations configurations) { 57 | this.configurations = configurations; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/beans/product/Plugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.beans.product; 18 | 19 | import javax.xml.bind.annotation.XmlAttribute; 20 | import javax.xml.bind.annotation.XmlRootElement; 21 | 22 | /** 23 | * Bean to represent a plugin. 24 | * 25 | * This is used to 26 | * [1] Capture build-time product file individual plugin data from distribution pom file. 27 | * [2] Write individual plugin data to carbon.product file. 28 | * 29 | * @since 3.1.0 30 | */ 31 | @XmlRootElement 32 | public class Plugin { 33 | 34 | private String id; 35 | private Boolean autoStart; 36 | private Integer startLevel; 37 | 38 | public Plugin() {} 39 | 40 | public Plugin(String id, Boolean autoStart, Integer startLevel) { 41 | this.setId(id); 42 | this.setAutoStart(autoStart); 43 | this.setStartLevel(startLevel); 44 | } 45 | 46 | public String getId() { 47 | return id; 48 | } 49 | 50 | @XmlAttribute 51 | public void setId(String id) { 52 | this.id = id; 53 | } 54 | 55 | @SuppressWarnings("unused") 56 | public Boolean getAutoStart() { 57 | return autoStart; 58 | } 59 | 60 | @XmlAttribute 61 | public void setAutoStart(Boolean autoStart) { 62 | this.autoStart = autoStart; 63 | } 64 | 65 | @SuppressWarnings("unused") 66 | public Integer getStartLevel() { 67 | return startLevel; 68 | } 69 | 70 | @XmlAttribute 71 | public void setStartLevel(Integer startLevel) { 72 | this.startLevel = startLevel; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/feature/install/Feature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.maven.p2.feature.install; 17 | 18 | import org.wso2.maven.p2.utils.BundleUtils; 19 | 20 | /** 21 | * Bean class representing a feature. 22 | * 23 | * @since 2.0.0 24 | */ 25 | public class Feature { 26 | 27 | private String id; 28 | private String version; 29 | 30 | /** 31 | * Returns the feature id representing this feature. If the given id ends with feature, .group is appended. 32 | * If the given does not ends with .feature.group, then .feature.group is appended. This is 33 | * necessary for the director application to work. 34 | * 35 | * @return String 36 | */ 37 | public String getId() { 38 | if (id != null && id.endsWith(".feature")) { 39 | return id + ".group"; 40 | } 41 | if (id != null && !id.endsWith(".feature.group")) { 42 | return id + ".feature.group"; 43 | } 44 | return id; 45 | } 46 | 47 | /** 48 | * Sets the feature id. 49 | * 50 | * @param id String 51 | */ 52 | public void setId(String id) { 53 | this.id = id; 54 | } 55 | 56 | /** 57 | * Returns the version of this feature in OSGI format. 58 | * i.e: If the maven version for this feature is 4.2.0-SNAPSHOT, the OSGI representation is 4.2.0.SNAPSHOT. 59 | * 60 | * @return String 61 | */ 62 | public String getVersion() { 63 | return BundleUtils.getOSGIVersion(version); 64 | } 65 | 66 | /** 67 | * Sets the version of this feature. 68 | * 69 | * @param version String 70 | */ 71 | public void setVersion(String version) { 72 | this.version = version; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Purpose 2 | > Describe the problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc. 3 | 4 | ## Goals 5 | > Describe the solutions that this feature/fix will introduce to resolve the problems described above 6 | 7 | ## Approach 8 | > Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here. 9 | 10 | ## User stories 11 | > Summary of user stories addressed by this change> 12 | 13 | ## Release note 14 | > Brief description of the new feature or bug fix as it will appear in the release notes 15 | 16 | ## Documentation 17 | > Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact 18 | 19 | ## Training 20 | > Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable 21 | 22 | ## Certification 23 | > Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why. 24 | 25 | ## Marketing 26 | > Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable 27 | 28 | ## Automation tests 29 | - Unit tests 30 | > Code coverage information 31 | - Integration tests 32 | > Details about the test cases and coverage 33 | 34 | ## Security checks 35 | - Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? yes/no 36 | - Ran FindSecurityBugs plugin and verified report? yes/no 37 | - Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? yes/no 38 | 39 | ## Samples 40 | > Provide high-level details about the samples related to this feature 41 | 42 | ## Related PRs 43 | > List any other related PRs 44 | 45 | ## Migrations (if applicable) 46 | > Describe migration steps and platforms on which migration has been tested 47 | 48 | ## Test environment 49 | > List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested 50 | 51 | ## Learning 52 | > Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem. -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/resources/META-INF/plexus/components.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | org.apache.maven.artifact.handler.ArtifactHandler 21 | carbon-feature 22 | org.apache.maven.artifact.handler.DefaultArtifactHandler 23 | 24 | 25 | carbon-feature 26 | zip 27 | carbon-feature 28 | java 29 | 30 | 31 | 32 | org.apache.maven.lifecycle.mapping.LifecycleMapping 33 | carbon-feature 34 | org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping 35 | 36 | 37 | 38 | default 39 | 40 | 41 | org.apache.maven.plugins:maven-install-plugin:install 42 | org.apache.maven.plugins:maven-deploy-plugin:deploy 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | org.apache.maven.artifact.handler.ArtifactHandler 51 | eclipse-repository 52 | 53 | org.apache.maven.artifact.handler.DefaultArtifactHandler 54 | 55 | 56 | zip 57 | eclipse-repository 58 | eclipse-repository 59 | java 60 | false 61 | false 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/repository/CatFeature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.maven.p2.repository; 17 | 18 | 19 | import org.apache.maven.plugin.MojoExecutionException; 20 | import org.apache.maven.project.MavenProject; 21 | import org.wso2.maven.p2.utils.BundleUtils; 22 | 23 | import java.util.Properties; 24 | import java.util.regex.Pattern; 25 | 26 | /** 27 | * Bean class representing a CatFeature object provided as an input param to RepositoryGeneratorMojo. 28 | * 29 | * @since 2.0.0 30 | */ 31 | public class CatFeature { 32 | 33 | /** 34 | * Id of the feature. 35 | * 36 | * @parameter 37 | * @required 38 | */ 39 | private String id; 40 | 41 | /** 42 | * Version of the feature. 43 | * 44 | * @parameter 45 | * @required 46 | */ 47 | private String version; 48 | 49 | /** 50 | * @parameter default-value="${project}" 51 | */ 52 | private MavenProject project; 53 | 54 | private boolean versionReplaced = false; 55 | 56 | public CatFeature() { 57 | 58 | } 59 | 60 | public String getId() { 61 | return id; 62 | } 63 | 64 | public void setId(String id) { 65 | this.id = id; 66 | } 67 | 68 | public String getVersion() throws MojoExecutionException { 69 | if (!versionReplaced) { 70 | replaceProjectKeysInVersion(project); 71 | } 72 | return BundleUtils.getOSGIVersion(version); 73 | } 74 | 75 | public void setVersion(String version) { 76 | this.version = version; 77 | } 78 | 79 | public void setProject(MavenProject project) { 80 | this.project = project; 81 | } 82 | 83 | public void replaceProjectKeysInVersion(MavenProject project) throws MojoExecutionException { 84 | if (version == null) { 85 | throw new MojoExecutionException("Could not find the version for featureId: " + getId()); 86 | } 87 | Properties properties = project.getProperties(); 88 | properties.forEach((key, value) -> { 89 | version = version.replaceAll(Pattern.quote("${" + key + "}"), value.toString()); 90 | }); 91 | versionReplaced = true; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/feature/generate/Feature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.feature.generate; 18 | 19 | import org.wso2.maven.p2.beans.CarbonArtifact; 20 | import org.wso2.maven.p2.utils.BundleUtils; 21 | 22 | /** 23 | * Bean class representing a Feature object provided as an input param to FeatureGenMojo. 24 | * 25 | * @since 2.0.0 26 | */ 27 | public class Feature extends CarbonArtifact { 28 | private String id; 29 | private boolean optional; 30 | 31 | /** 32 | * Returns the feature id represented by this Feature. 33 | *

34 | * If the name of the feature id ends with '.feature', then '.feature' word is removed and the result is 35 | * returned. 36 | *

37 | * 38 | * @return String feature id. 39 | */ 40 | public String getId() { 41 | if (id != null && id.endsWith(".feature")) { 42 | return id.substring(0, id.lastIndexOf(".feature")); 43 | } 44 | return id; 45 | } 46 | 47 | /** 48 | * Sets the feature version for the given feature. 49 | * 50 | * @param id String 51 | */ 52 | public void setId(String id) { 53 | this.id = id; 54 | } 55 | 56 | /** 57 | * Returns whether this particular feature is optional or not. This is considered when generating the feature.xml 58 | * 59 | * @return true if this feature is optional 60 | */ 61 | public boolean isOptional() { 62 | return this.optional; 63 | } 64 | 65 | /** 66 | * Sets whether this feature is optional or not. This is applicable only to included features. 67 | *

68 | * Note: There is no usage of this method in the plugin code. However, this is used by plexus container to inject 69 | * the value. 70 | *

71 | * 72 | * @param optional boolean 73 | */ 74 | public void setOptional(boolean optional) { 75 | this.optional = optional; 76 | } 77 | 78 | /** 79 | * Returns the Feature version in OSGI format. 80 | *

81 | * i.e: If the maven version for this artifact is 4.2.0-SNAPSHOT, this will return 4.2.0.SNAPSHOT 82 | *

83 | * 84 | * @return String 85 | */ 86 | public String getFeatureVersion() { 87 | return BundleUtils.getOSGIVersion(super.getVersion()); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/repository/Category.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.maven.p2.repository; 17 | 18 | import org.apache.maven.plugin.MojoExecutionException; 19 | import org.apache.maven.project.MavenProject; 20 | 21 | import java.util.ArrayList; 22 | 23 | /** 24 | * Bean class representing a Category object provided as an input param to RepositoryGeneratorMojo. 25 | * 26 | * @since 2.0.0 27 | */ 28 | public class Category { 29 | 30 | /** 31 | * Category Id. 32 | * 33 | * @parameter 34 | * @required 35 | */ 36 | private String id; 37 | 38 | /** 39 | * Category Label. 40 | * 41 | * @parameter 42 | */ 43 | private String label; 44 | 45 | /** 46 | * Category description. 47 | * 48 | * @parameter 49 | */ 50 | private String description; 51 | 52 | /** 53 | * List of features contained in the category. 54 | * 55 | * @parameter 56 | * @required 57 | */ 58 | private ArrayList features; 59 | 60 | private ArrayList processedFeatures; 61 | 62 | public ArrayList getFeatures() { 63 | return features; 64 | } 65 | 66 | public void setFeatures(ArrayList features) { 67 | this.features = features; 68 | } 69 | 70 | public ArrayList getProcessedFeatures(MavenProject project) throws MojoExecutionException { 71 | if (processedFeatures != null) { 72 | return processedFeatures; 73 | } 74 | if (features == null || features.size() == 0) { 75 | return null; 76 | } 77 | processedFeatures = new ArrayList<>(); 78 | for (CatFeature f : features) { 79 | processedFeatures.add(f); 80 | f.replaceProjectKeysInVersion(project); 81 | } 82 | return processedFeatures; 83 | } 84 | 85 | public String getId() { 86 | return id; 87 | } 88 | 89 | public void setId(String id) { 90 | this.id = id; 91 | } 92 | 93 | public String getLabel() { 94 | if (label == null) { 95 | return getId(); 96 | } else { 97 | return label; 98 | } 99 | } 100 | 101 | public void setLabel(String label) { 102 | this.label = label; 103 | } 104 | 105 | public void setDescription(String description) { 106 | this.description = description; 107 | } 108 | 109 | public String getDescription() { 110 | if (description == null) { 111 | return getLabel(); 112 | } else { 113 | return description; 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/utils/PropertyReplacer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.maven.p2.utils; 17 | 18 | 19 | import java.util.Properties; 20 | 21 | /** 22 | * Util class which get the property variable of the form ${variable} to actual value. 23 | * 24 | * @since 2.0.0 25 | */ 26 | public class PropertyReplacer { 27 | // States of the state machine 28 | private enum State { 29 | NORMAL, SEEN_DOLLAR, WITHIN_BRACKET 30 | } 31 | 32 | /** 33 | * When a property is encountered in ${variable} form, traverse through the given Properties collection and 34 | * update it to the actual value. 35 | * 36 | * @param origString String key in the form of ${variable} 37 | * @param props Properties object 38 | * @return actual String value represented by the orgString 39 | */ 40 | public static String replaceProperties(final String origString, final Properties props) { 41 | 42 | final char[] chars = origString.toCharArray(); 43 | StringBuilder buffer = new StringBuilder(); 44 | boolean properties = false; 45 | State state = State.NORMAL; 46 | int start = 0; 47 | for (int i = 0; i < chars.length; ++i) { 48 | 49 | char c = chars[i]; 50 | if (c == '$' && state != State.WITHIN_BRACKET) { // found a "$" 51 | state = State.SEEN_DOLLAR; 52 | } else if (c == '{' && state == State.SEEN_DOLLAR) { // found a "{" after "$" 53 | buffer.append(origString.substring(start, i - 1)); 54 | state = State.WITHIN_BRACKET; 55 | start = i - 1; 56 | } else if (state == State.SEEN_DOLLAR) { // just a single "$" ; no brackets 57 | state = State.NORMAL; 58 | } else if (c == '}' && state == State.WITHIN_BRACKET) { // its a ${property} sequence extract the value 59 | String key = origString.substring(start + 2, i); 60 | String value = props.getProperty(key); 61 | if (value != null) { // if the value of the property found; replace 62 | properties = true; 63 | buffer.append(value); 64 | } else { // if the value of the property not give do not replace 65 | buffer.append("${"); 66 | buffer.append(key); 67 | buffer.append('}'); 68 | } 69 | start = i + 1; 70 | state = State.NORMAL; 71 | } 72 | } 73 | // No properties hence returning the original string 74 | if (!properties) { 75 | return origString; 76 | } 77 | // Collect the trailing characters 78 | if (start != chars.length) { 79 | buffer.append(origString.substring(start, chars.length)); 80 | } 81 | return buffer.toString(); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/feature/uninstall/FeatureUnInstallMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.feature.uninstall; 18 | 19 | import org.apache.maven.plugin.AbstractMojo; 20 | import org.apache.maven.plugin.MojoExecutionException; 21 | import org.apache.maven.plugin.MojoFailureException; 22 | import org.apache.maven.plugins.annotations.Component; 23 | import org.apache.maven.plugins.annotations.LifecyclePhase; 24 | import org.apache.maven.plugins.annotations.Mojo; 25 | import org.apache.maven.plugins.annotations.Parameter; 26 | import org.apache.maven.project.MavenProject; 27 | import org.eclipse.sisu.equinox.launching.internal.P2ApplicationLauncher; 28 | 29 | import java.util.List; 30 | 31 | /** 32 | * Mojo which will uninstall a given set of carbon features from a product. 33 | * 34 | * @since 2.0.0 35 | */ 36 | @Mojo(name = "uninstall", defaultPhase = LifecyclePhase.PACKAGE) 37 | public class FeatureUnInstallMojo extends AbstractMojo { 38 | 39 | /** 40 | * Destination to which the features should be installed. 41 | */ 42 | @Parameter(required = true) 43 | private String destination; 44 | /** 45 | * Target runtime. 46 | */ 47 | @Parameter(required = true) 48 | private String runtime; 49 | 50 | /** 51 | * List of features. 52 | */ 53 | @Parameter(required = true) 54 | private List features; 55 | 56 | @Parameter(defaultValue = "${project}") 57 | private MavenProject project; 58 | 59 | @Component 60 | private P2ApplicationLauncher launcher; 61 | 62 | /** 63 | * Kill the forked test process after a certain number of seconds. If set to 0, wait forever for 64 | * the process, never timing out. 65 | * 66 | * @parameter expression="${p2.timeout}" 67 | */ 68 | @Parameter(defaultValue = "${p2.timeout}") 69 | private int forkedProcessTimeoutInSeconds; 70 | 71 | 72 | /** 73 | * Overridden method of AbstractMojo class. This is picked up by the maven runtime for execution. 74 | * 75 | * @throws MojoExecutionException throws when any runtime exception occurs. i.e: fail to read write file, fail to 76 | * parse a configuration xml 77 | * @throws MojoFailureException throws when the tool breaks for any configuration issues 78 | */ 79 | public void execute() throws MojoExecutionException, MojoFailureException { 80 | FeatureUnInstaller unInstaller = new FeatureUnInstaller(); 81 | unInstaller.setDestination(this.destination); 82 | unInstaller.setFeatures(this.features); 83 | unInstaller.setLauncher(this.launcher); 84 | unInstaller.setProfile(this.runtime); 85 | unInstaller.setProject(this.project); 86 | unInstaller.setForkedProcessTimeoutInSeconds(this.forkedProcessTimeoutInSeconds); 87 | 88 | this.getLog().info("Running Equinox P2 Director Application"); 89 | unInstaller.uninstallFeatures(); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/utils/MavenUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.maven.p2.utils; 17 | 18 | import org.apache.maven.artifact.Artifact; 19 | import org.apache.maven.artifact.repository.ArtifactRepository; 20 | import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; 21 | import org.apache.maven.repository.RepositorySystem; 22 | import org.wso2.maven.p2.beans.CarbonArtifact; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Util class responsible for resolving maven artifacts. 28 | * 29 | * @since 2.0.0 30 | */ 31 | public class MavenUtils { 32 | 33 | /** 34 | * Returns an artifact which represented by a the given CarbonArtifact. 35 | * 36 | * @param carbonArtifact carbon artifact whose maven artifact needs to be resolved 37 | * @param repositorySystem RepositorySystem object 38 | * @param remoteRepositories collection of remote repositories 39 | * @param localRepository local repository representation 40 | * @return resolved maven artifact 41 | */ 42 | public static Artifact getResolvedArtifact(CarbonArtifact carbonArtifact, 43 | RepositorySystem repositorySystem, 44 | List remoteRepositories, 45 | ArtifactRepository localRepository) { 46 | 47 | return getResolvedArtifact(carbonArtifact.getGroupId(), carbonArtifact.getArtifactId(), 48 | carbonArtifact.getVersion(), repositorySystem, remoteRepositories, localRepository, 49 | carbonArtifact.getType()); 50 | 51 | } 52 | 53 | /** 54 | * Returns an artifact which represented by a the given CarbonArtifact. 55 | * 56 | * @param groupId {@code String} group id of the maven artifact 57 | * @param artifactId {@code String} artifact id of the maven artifact 58 | * @param version {@code String} version of the maven artifact 59 | * @param repositorySystem {@link RepositorySystem} 60 | * @param remoteRepositories {@code List} 61 | * @param localRepository {@link ArtifactRepository} 62 | * @param type {@code String} 63 | * @return {@link Artifact} 64 | */ 65 | private static Artifact getResolvedArtifact(String groupId, String artifactId, String version, 66 | RepositorySystem repositorySystem, 67 | List remoteRepositories, 68 | ArtifactRepository localRepository, String type) { 69 | 70 | Artifact artifact = repositorySystem.createArtifact(groupId, artifactId, version, Artifact.SCOPE_RUNTIME, type); 71 | 72 | ArtifactResolutionRequest request = new ArtifactResolutionRequest(); 73 | request.setArtifact(artifact); 74 | request.setLocalRepository(localRepository); 75 | request.setRemoteRepositories(remoteRepositories); 76 | repositorySystem.resolve(request); 77 | 78 | return artifact; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/utils/P2Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.maven.p2.utils; 17 | 18 | /** 19 | * Contains P2 related constants. File is kept to preserve the history in case if needed later. 20 | * 21 | * @since 1.0.0 22 | */ 23 | public class P2Constants { 24 | 25 | /** 26 | * Prevent instantiating the Constants class. 27 | */ 28 | private P2Constants() {} 29 | 30 | public static final String DEFAULT_PROFILE_ID = "WSO2CarbonProfile"; 31 | public static final String P2_DIRECTORY = "@config.dir/../lib/p2/"; 32 | public static final String LIB = "lib"; 33 | public static final String P2 = "p2"; 34 | public static final String DEFAULT_ENCODING = "UTF-8"; 35 | 36 | /** 37 | * Launcher Constants. 38 | */ 39 | public static class Launcher { 40 | public static final String METADATA_REPOSITORY = "-metadataRepository"; 41 | public static final String ARTIFACT_REPOSITORY = "-artifactRepository"; 42 | public static final String DESTINATION = "-destination"; 43 | public static final String BUNDLEPOOL = "-bundlepool"; 44 | public static final String SHARED = "-shared"; 45 | public static final String PROFILE = "-profile"; 46 | public static final String PROFILE_PROPERTIES = "-profileProperties"; 47 | public static final String ECLIPSE_UPDATE_FEATURE_TRUE = "org.eclipse.update.install.features=true"; 48 | public static final String ROAMING = "-roaming"; 49 | public static final String INSTALLIU = "-installIU"; 50 | } 51 | 52 | /** 53 | * Constants class related to product file default settings. 54 | */ 55 | public static class ProductFile { 56 | public static final String NAME = "carbon.product"; 57 | public static final String TARGET_DIRECTORY = "target"; 58 | public static final Float XML_VERSION = 1.0F; 59 | public static final Float PDE_VERSION = 3.5F; 60 | 61 | /** 62 | * Constants class related to Product element default settings of product file. 63 | */ 64 | public static class Product { 65 | public static final String NAME = "Carbon Product"; 66 | public static final String UID = "carbon.product.id"; 67 | public static final String ID = "carbon.product"; 68 | public static final String APPLICATION = "carbon.application"; 69 | public static final String OSGI_RUNTIME_FEATURE = "org.wso2.carbon.osgi"; 70 | public static final Boolean USE_FEATURES = false; 71 | public static final Boolean INCLUDE_LAUNCHERS = true; 72 | public static final String CONFIG_INI_USE = "default"; 73 | public static final String LAUNCHER_NAME = "eclipse"; 74 | } 75 | 76 | /** 77 | * Constants class related to default character replacement settings of 78 | * version values appearing in a product file. 79 | */ 80 | public static class Feature { 81 | public static final String VERSION_CHAR_REPLACEMENT = "."; 82 | public static final String VERSION_CHAR_REPLACED = "-"; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /carbon-feature-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | org.wso2.carbon.maven 21 | carbon-maven-plugins 22 | 3.1.6-SNAPSHOT 23 | ../pom.xml 24 | 25 | 26 | 4.0.0 27 | carbon-feature-plugin 28 | maven-plugin 29 | 3.1.6-SNAPSHOT 30 | Carbon Maven Plugins - Carbon Feature Plugin 31 | 32 | 33 | 34 | org.apache.maven 35 | maven-plugin-api 36 | 37 | 38 | org.apache.maven 39 | maven-core 40 | 41 | 42 | org.apache.maven 43 | maven-project 44 | 45 | 46 | junit 47 | junit 48 | test 49 | 50 | 51 | org.apache.maven.plugin-tools 52 | maven-plugin-annotations 53 | 54 | 55 | org.eclipse.tycho 56 | sisu-equinox-launching 57 | 58 | 59 | org.eclipse.tycho 60 | tycho-p2-director-plugin 61 | 62 | 63 | org.eclipse.tycho 64 | tycho-core 65 | 66 | 67 | 68 | 69 | 70 | 71 | org.apache.rat 72 | apache-rat-plugin 73 | 74 | 75 | src/**/* 76 | pom.xml 77 | 78 | 79 | 80 | 81 | verify 82 | 83 | check 84 | 85 | 86 | 87 | 88 | 89 | org.apache.maven.plugins 90 | maven-plugin-plugin 91 | ${maven.plugin.plugin.version} 92 | 93 | 94 | true 95 | 96 | 97 | 98 | mojo-descriptor 99 | 100 | descriptor 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/repository/RepositoryGeneratorMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.maven.p2.repository; 17 | 18 | import org.apache.maven.artifact.repository.ArtifactRepository; 19 | import org.apache.maven.plugin.AbstractMojo; 20 | import org.apache.maven.plugin.MojoExecutionException; 21 | import org.apache.maven.plugin.MojoFailureException; 22 | import org.apache.maven.plugins.annotations.Component; 23 | import org.apache.maven.plugins.annotations.LifecyclePhase; 24 | import org.apache.maven.plugins.annotations.Mojo; 25 | import org.apache.maven.plugins.annotations.Parameter; 26 | import org.apache.maven.project.MavenProject; 27 | import org.apache.maven.repository.RepositorySystem; 28 | import org.eclipse.sisu.equinox.launching.internal.P2ApplicationLauncher; 29 | 30 | import java.net.URL; 31 | import java.util.List; 32 | 33 | /** 34 | * Write environment information for the current build to file. 35 | * 36 | * @since 2.0.0 37 | */ 38 | @Mojo(name = "generate-repo", defaultPhase = LifecyclePhase.PACKAGE) 39 | public class RepositoryGeneratorMojo extends AbstractMojo { 40 | 41 | @Parameter 42 | private String name; 43 | 44 | @Parameter 45 | private URL targetRepository; 46 | 47 | @Parameter(required = true) 48 | private List features; 49 | 50 | @Parameter 51 | private List bundles; 52 | 53 | @Parameter 54 | private List categories; 55 | 56 | @Parameter(defaultValue = "${project}") 57 | private MavenProject project; 58 | 59 | @Parameter(defaultValue = "false") 60 | private boolean archive; 61 | 62 | @Component 63 | private RepositorySystem repositorySystem; 64 | 65 | @Parameter(defaultValue = "${localRepository}") 66 | private ArtifactRepository localRepository; 67 | 68 | 69 | @Parameter(defaultValue = "${project.remoteArtifactRepositories}") 70 | private List remoteRepositories; 71 | 72 | 73 | @Component 74 | private P2ApplicationLauncher launcher; 75 | 76 | /** 77 | * Kill the forked test process after a certain number of seconds. If set to 0, wait forever for 78 | * the process, never timing out. 79 | */ 80 | @Parameter(defaultValue = "${p2.timeout}") 81 | private int forkedProcessTimeoutInSeconds; 82 | 83 | /** 84 | * Overridden method, which will be picked up by maven execution context and execute when this mojo is referred. 85 | * 86 | * @throws MojoExecutionException throws when the tool breaks for any configuration issues 87 | * @throws MojoFailureException throws when any runtime exception occurs. i.e: When director application fails 88 | * to generate the repository 89 | */ 90 | public void execute() throws MojoExecutionException, MojoFailureException { 91 | RepositoryGenerator generator = constructRepoGenerator(); 92 | generator.generate(); 93 | } 94 | 95 | private RepositoryGenerator constructRepoGenerator() { 96 | RepositoryResourceBundle resourceBundle = new RepositoryResourceBundle(); 97 | resourceBundle.setName(this.name); 98 | resourceBundle.setRepository(this.targetRepository); 99 | resourceBundle.setFeatureArtifacts(this.features); 100 | resourceBundle.setBundleArtifacts(this.bundles); 101 | resourceBundle.setCategories(this.categories); 102 | resourceBundle.setProject(this.project); 103 | resourceBundle.setArchive(this.archive); 104 | resourceBundle.setRepositorySystem(this.repositorySystem); 105 | resourceBundle.setLocalRepository(this.localRepository); 106 | resourceBundle.setRemoteRepositories(this.remoteRepositories); 107 | resourceBundle.setLauncher(this.launcher); 108 | resourceBundle.setForkedProcessTimeoutInSeconds(this.forkedProcessTimeoutInSeconds); 109 | resourceBundle.setLog(getLog()); 110 | return new RepositoryGenerator(resourceBundle); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/feature/uninstall/FeatureUnInstaller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.feature.uninstall; 18 | 19 | import org.apache.maven.plugin.MojoFailureException; 20 | import org.apache.maven.project.MavenProject; 21 | import org.eclipse.sisu.equinox.launching.internal.P2ApplicationLauncher; 22 | import org.wso2.maven.p2.utils.P2ApplicationLaunchManager; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * FeatureUninstaller takes configuration data from FeatureUninstallMojo and perform the uninstall task. 28 | * 29 | * @since 2.0.0 30 | */ 31 | public class FeatureUnInstaller { 32 | 33 | private String destination; 34 | private String profile; 35 | private List features; 36 | private MavenProject project; 37 | private P2ApplicationLauncher launcher; 38 | private int forkedProcessTimeoutInSeconds; 39 | 40 | private static final String PUBLISHER_APPLICATION = "org.eclipse.equinox.p2.director"; 41 | 42 | /** 43 | * Default constructor which is executed during object creation of this class. 44 | * 45 | * @throws MojoFailureException throws when the director application fail to uninstall any given feature. 46 | */ 47 | public void uninstallFeatures() throws MojoFailureException { 48 | String iUs = getIUsToUninstall(); 49 | uninstallFeatures(iUs); 50 | } 51 | 52 | /** 53 | * Analyze the given set of features and generate the string containing metadata about all the features to be 54 | * uninstalled. 55 | * 56 | * @return String representing metadata about the features to be uninstalled 57 | */ 58 | private String getIUsToUninstall() { 59 | if (features == null) { 60 | return null; 61 | } 62 | StringBuilder uninstallUIs = new StringBuilder(); 63 | features.forEach(feature -> 64 | uninstallUIs.append(feature.getId().trim()).append("/").append(feature.getVersion().trim()). 65 | append(",")); 66 | return uninstallUIs.toString(); 67 | } 68 | 69 | /** 70 | * Uninstall the set of features given as a collection of IUs. 71 | * 72 | * @param uninstallUIs comma separated list of IUs 73 | * @throws MojoFailureException throws when the director application fail to uninstall any given feature. 74 | */ 75 | private void uninstallFeatures(String uninstallUIs) throws MojoFailureException { 76 | if (project != null) { 77 | P2ApplicationLaunchManager launcher = new P2ApplicationLaunchManager(this.launcher); 78 | launcher.setWorkingDirectory(project.getBasedir()); 79 | launcher.setApplicationName(PUBLISHER_APPLICATION); 80 | launcher.addArgumentsToUnInstallFeatures(uninstallUIs, destination, profile); 81 | launcher.performAction(forkedProcessTimeoutInSeconds); 82 | } 83 | } 84 | 85 | /** 86 | * Sets the location of the profile. 87 | * 88 | * @param destination {@code String} 89 | */ 90 | public void setDestination(String destination) { 91 | this.destination = destination; 92 | } 93 | 94 | /** 95 | * Sets the string profile name of which the features needs to be uninstalled. 96 | * 97 | * @param profile {@code String} 98 | */ 99 | public void setProfile(String profile) { 100 | this.profile = profile; 101 | } 102 | 103 | /** 104 | * Sets the features to be uninstalled. 105 | * 106 | * @param features {@code List} 107 | */ 108 | public void setFeatures(List features) { 109 | this.features = features; 110 | } 111 | 112 | /** 113 | * Sets the MavenProject injected by the maven runtime. 114 | * 115 | * @param project {@code MavenProject} 116 | */ 117 | public void setProject(MavenProject project) { 118 | this.project = project; 119 | } 120 | 121 | /** 122 | * Sets the P2ApplicationLauncher injected by maven runtime. 123 | * 124 | * @param launcher {@code P2ApplicationLauncher} 125 | */ 126 | public void setLauncher(P2ApplicationLauncher launcher) { 127 | this.launcher = launcher; 128 | } 129 | 130 | /** 131 | * Sets forkedProcessTimeout in seconds. This is needed for P2ApplicationLauncher. 132 | * 133 | * @param forkedProcessTimeoutInSeconds {@code int} 134 | */ 135 | public void setForkedProcessTimeoutInSeconds(int forkedProcessTimeoutInSeconds) { 136 | this.forkedProcessTimeoutInSeconds = forkedProcessTimeoutInSeconds; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/utils/StandaloneManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.maven.p2.utils; 17 | 18 | import org.apache.maven.plugin.MojoFailureException; 19 | import org.eclipse.sisu.equinox.launching.EquinoxLauncher; 20 | import org.eclipse.sisu.equinox.launching.internal.EquinoxInstallationLaunchConfiguration; 21 | import org.eclipse.tycho.launching.LaunchConfiguration; 22 | 23 | import java.io.File; 24 | import java.nio.file.Paths; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * Eclipse installations using the p2 director application. 30 | * This director runtime can install products with meta-requirements, 31 | * e.g. for custom touchpoint actions 32 | * 33 | * @since 3.0.0 34 | */ 35 | public class StandaloneManager { 36 | 37 | private final EquinoxLauncher launcher; 38 | private File runtimeLocation; 39 | private List programArguments; 40 | 41 | public StandaloneManager(EquinoxLauncher launcher) { 42 | this.launcher = launcher; 43 | programArguments = new ArrayList<>(); 44 | } 45 | 46 | /** 47 | * Sets the Runtime Location. 48 | * 49 | * @param runtimeLocation {@link File} 50 | */ 51 | public void setRuntimeLocation(File runtimeLocation) { 52 | this.runtimeLocation = runtimeLocation; 53 | } 54 | 55 | /** 56 | * Sets the StandaloneDirectorRuntime's arguments to install features. 57 | * 58 | * @param repositoryLocation a comma separated list of metadata repository (or artifact repository as 59 | * in p2 both 60 | * metadata and artifacts resides in the same repo) URLs where the software 61 | * to be 62 | * installed can be found. 63 | * of the feature has to be suffixed with ".feature.group". 64 | * @param destination the path of a folder in which the targeted product is located. 65 | * @param profile the profile id containing the description of the targeted product. This 66 | * ID is 67 | * defined by the eclipse.p2.profile property contained in the config.ini of the 68 | * targeted product. 69 | */ 70 | public void addArgumentsToInstallFeatures(String repositoryLocation, String destination, String profile) { 71 | programArguments.add(P2Constants.Launcher.METADATA_REPOSITORY); 72 | programArguments.add(repositoryLocation); 73 | programArguments.add(P2Constants.Launcher.ARTIFACT_REPOSITORY); 74 | programArguments.add(repositoryLocation); 75 | programArguments.add(P2Constants.Launcher.DESTINATION); 76 | programArguments.add(Paths.get(destination, profile).toString()); 77 | programArguments.add(P2Constants.Launcher.BUNDLEPOOL); 78 | programArguments.add(Paths.get(destination, P2Constants.LIB).toString()); 79 | programArguments.add(P2Constants.Launcher.SHARED); 80 | programArguments.add(Paths.get(destination, P2Constants.LIB, P2Constants.P2).toString()); 81 | programArguments.add(P2Constants.Launcher.PROFILE); 82 | programArguments.add(profile); 83 | programArguments.add(P2Constants.Launcher.PROFILE_PROPERTIES); 84 | programArguments.add(P2Constants.Launcher.ECLIPSE_UPDATE_FEATURE_TRUE); 85 | programArguments.add(P2Constants.Launcher.ROAMING); 86 | } 87 | 88 | /** 89 | * Calls the Eclipse Launcher to perform the action such as install the set of features. 90 | * 91 | * @param installIU The feature (UI) that is to be install. 92 | * @param forkedProcessTimeoutInSeconds int 93 | * @throws MojoFailureException throws when unable to perform the p2 activity 94 | */ 95 | public void performAction(String installIU, int forkedProcessTimeoutInSeconds) throws MojoFailureException { 96 | int index = programArguments.indexOf(P2Constants.Launcher.INSTALLIU); 97 | if (index >= 0) { 98 | programArguments.set(index + 1, installIU); 99 | } else { 100 | programArguments.add(P2Constants.Launcher.INSTALLIU); 101 | programArguments.add(installIU); 102 | } 103 | 104 | LaunchConfiguration launch = new EquinoxInstallationLaunchConfiguration(runtimeLocation, programArguments); 105 | int result = launcher.execute(launch, forkedProcessTimeoutInSeconds); 106 | if (result != 0) { 107 | throw new MojoFailureException("P2 publisher return code was " + result); 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/repository/RepositoryResourceBundle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.repository; 18 | 19 | import org.apache.maven.artifact.repository.ArtifactRepository; 20 | import org.apache.maven.plugin.logging.Log; 21 | import org.apache.maven.project.MavenProject; 22 | import org.apache.maven.repository.RepositorySystem; 23 | import org.eclipse.sisu.equinox.launching.internal.P2ApplicationLauncher; 24 | 25 | import java.net.URL; 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | 30 | /** 31 | * Bean class containing all the parameters entered to the mojo through plugin configuration. 32 | * The purpose of this class is to make any configuration property accessible from any class by simply passing this 33 | * bean as a parameter. 34 | * 35 | * @since 2.0.0 36 | */ 37 | public class RepositoryResourceBundle { 38 | 39 | private String name; 40 | private URL repository; 41 | 42 | private List featureArtifacts; 43 | private List bundleArtifacts; 44 | private List categories; 45 | 46 | private MavenProject project; 47 | 48 | 49 | private boolean archive; 50 | 51 | private RepositorySystem repositorySystem; 52 | private ArtifactRepository localRepository; 53 | private List remoteRepositories; 54 | private P2ApplicationLauncher launcher; 55 | private int forkedProcessTimeoutInSeconds; 56 | 57 | private Log log; 58 | 59 | public String getName() { 60 | return name; 61 | } 62 | 63 | 64 | public void setName(String name) { 65 | this.name = name; 66 | } 67 | 68 | public URL getRepository() { 69 | return repository; 70 | } 71 | 72 | public void setRepository(URL repository) { 73 | this.repository = repository; 74 | } 75 | 76 | public List getFeatureArtifacts() { 77 | if (featureArtifacts == null) { 78 | return new ArrayList<>(); 79 | } 80 | return featureArtifacts; 81 | } 82 | 83 | public void setFeatureArtifacts(List featureArtifacts) { 84 | this.featureArtifacts = featureArtifacts; 85 | } 86 | 87 | public List getBundleArtifacts() { 88 | if (bundleArtifacts == null) { 89 | return new ArrayList<>(); 90 | } 91 | return bundleArtifacts; 92 | } 93 | 94 | public void setBundleArtifacts(List bundleArtifacts) { 95 | this.bundleArtifacts = bundleArtifacts; 96 | } 97 | 98 | public List getCategories() { 99 | return categories; 100 | } 101 | 102 | public void setCategories(List categories) { 103 | this.categories = categories; 104 | } 105 | 106 | public MavenProject getProject() { 107 | return project; 108 | } 109 | 110 | public void setProject(MavenProject project) { 111 | this.project = project; 112 | } 113 | 114 | public boolean isArchive() { 115 | return archive; 116 | } 117 | 118 | public void setArchive(boolean archive) { 119 | this.archive = archive; 120 | } 121 | 122 | public RepositorySystem getRepositorySystem() { 123 | return repositorySystem; 124 | } 125 | 126 | public void setRepositorySystem(RepositorySystem repositorySystem) { 127 | this.repositorySystem = repositorySystem; 128 | } 129 | 130 | public ArtifactRepository getLocalRepository() { 131 | return localRepository; 132 | } 133 | 134 | public void setLocalRepository(ArtifactRepository localRepository) { 135 | this.localRepository = localRepository; 136 | } 137 | 138 | public List getRemoteRepositories() { 139 | return remoteRepositories; 140 | } 141 | 142 | public void setRemoteRepositories(List remoteRepositories) { 143 | this.remoteRepositories = remoteRepositories; 144 | } 145 | 146 | public P2ApplicationLauncher getLauncher() { 147 | return launcher; 148 | } 149 | 150 | public void setLauncher(P2ApplicationLauncher launcher) { 151 | this.launcher = launcher; 152 | } 153 | 154 | public int getForkedProcessTimeoutInSeconds() { 155 | return forkedProcessTimeoutInSeconds; 156 | } 157 | 158 | public void setForkedProcessTimeoutInSeconds(int forkedProcessTimeoutInSeconds) { 159 | this.forkedProcessTimeoutInSeconds = forkedProcessTimeoutInSeconds; 160 | } 161 | 162 | public Log getLog() { 163 | return log; 164 | } 165 | 166 | public void setLog(Log log) { 167 | this.log = log; 168 | } 169 | 170 | } 171 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/product/PublishProductMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.maven.p2.product; 17 | 18 | import org.apache.maven.plugin.AbstractMojo; 19 | import org.apache.maven.plugin.MojoExecutionException; 20 | import org.apache.maven.plugin.MojoFailureException; 21 | import org.apache.maven.plugins.annotations.Component; 22 | import org.apache.maven.plugins.annotations.Mojo; 23 | import org.apache.maven.plugins.annotations.Parameter; 24 | import org.apache.maven.project.MavenProject; 25 | import org.eclipse.sisu.equinox.launching.internal.P2ApplicationLauncher; 26 | import org.wso2.maven.p2.beans.product.config.ProductFileConfig; 27 | import org.wso2.maven.p2.utils.P2ApplicationLaunchManager; 28 | import org.wso2.maven.p2.utils.ProductFileUtils; 29 | 30 | import java.io.File; 31 | import java.io.IOException; 32 | import java.net.URL; 33 | import java.nio.file.Paths; 34 | import javax.xml.bind.JAXBException; 35 | 36 | /** 37 | * Publish a given product using the .product file to the repository. 38 | * 39 | * @since 2.0.0 40 | */ 41 | @Mojo(name = "publish-product") 42 | public class PublishProductMojo extends AbstractMojo { 43 | 44 | @Parameter(defaultValue = "${project}") 45 | protected MavenProject project; 46 | 47 | @Parameter 48 | private URL repositoryURL; 49 | 50 | @Parameter 51 | private String executable; 52 | 53 | /** 54 | * The product configuration, a .product file. This file manages all aspects 55 | * of a product definition from its constituent plug-ins to configuration 56 | * files to branding. 57 | */ 58 | @Parameter 59 | private File productConfigurationFile; 60 | 61 | /** 62 | * Bean to capture build-time product file customizations 63 | * from pom level configurations. 64 | */ 65 | @Parameter 66 | private ProductFileConfig productFileConfig = new ProductFileConfig(); 67 | 68 | @Component 69 | private P2ApplicationLauncher launcher; 70 | 71 | /** 72 | * Kill the forked test process after a certain number of seconds. If set to 0, wait forever for 73 | * the process, never timing out. 74 | */ 75 | @Parameter(defaultValue = "${p2.timeout}") 76 | private int forkedProcessTimeoutInSeconds; 77 | 78 | /** 79 | * Overridden method of AbstractMojo class. This is picked up by the maven runtime for execution. 80 | * 81 | * @throws MojoExecutionException throws when any runtime exception occurs. i.e: fail to read write file, fail to 82 | * parse a configuration xml 83 | * @throws MojoFailureException throws when the tool breaks for any configuration issues 84 | */ 85 | public void execute() throws MojoExecutionException, MojoFailureException { 86 | try { 87 | publishProduct(); 88 | } catch (IOException e) { 89 | throw new MojoExecutionException("Cannot generate P2 metadata", e); 90 | } 91 | } 92 | 93 | /** 94 | * Perform the product publish action. 95 | * 96 | * @throws MojoFailureException throws when the tool breaks for any configuration issues. 97 | * @throws MojoExecutionException throws when any runtime exception occurs. 98 | * i.e: fail to read write file, fail to parse a configuration xml. 99 | * @throws IOException throws if fail to read file canonical path. 100 | */ 101 | private void publishProduct() throws MojoFailureException, MojoExecutionException, IOException { 102 | P2ApplicationLaunchManager p2LaunchManager = new P2ApplicationLaunchManager(launcher); 103 | p2LaunchManager.setWorkingDirectory(project.getBasedir()); 104 | p2LaunchManager.setApplicationName("org.eclipse.equinox.p2.publisher.ProductPublisher"); 105 | 106 | if (productConfigurationFile != null) { 107 | p2LaunchManager.addPublishProductArguments(repositoryURL, productConfigurationFile, executable); 108 | } else { 109 | // going ahead with a dynamically generated product file during build-time 110 | File productFile = Paths.get(ProductFileUtils.getProductFilePath(project)).toFile(); 111 | if (!productFile.exists()) { 112 | try { 113 | ProductFileUtils.generateProductFile(productFileConfig, project); 114 | } catch (JAXBException e) { 115 | throw new MojoExecutionException("Cannot proceed as there is an error in " + 116 | "writing configurations to product file.", e); 117 | } 118 | } 119 | p2LaunchManager.addPublishProductArguments(repositoryURL, productFile, executable); 120 | } 121 | p2LaunchManager.performAction(forkedProcessTimeoutInSeconds); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | org.wso2 20 | wso2 21 | 5 22 | 23 | 24 | 4.0.0 25 | org.wso2.carbon.maven 26 | carbon-maven-plugins 27 | pom 28 | 3.1.6-SNAPSHOT 29 | Carbon Maven Plugins - Parent Pom 30 | http://wso2.org 31 | 32 | 33 | https://github.com/wso2/carbon-maven-plugins.git 34 | scm:git:https://github.com/wso2/carbon-maven-plugins.git 35 | scm:git:https://github.com/wso2/carbon-maven-plugins.git 36 | HEAD 37 | 38 | 39 | 40 | carbon-feature-plugin 41 | 42 | 43 | 44 | 45 | 46 | org.apache.maven 47 | maven-plugin-api 48 | ${org.apache.maven.plugin.api.version} 49 | 50 | 51 | org.apache.maven 52 | maven-core 53 | ${org.apache.maven.core.version} 54 | 55 | 56 | org.apache.maven 57 | maven-project 58 | ${org.apache.maven.project.version} 59 | 60 | 61 | junit 62 | junit 63 | ${junit.version} 64 | test 65 | 66 | 67 | org.apache.maven.plugin-tools 68 | maven-plugin-annotations 69 | ${maven.plugin.annotation.version} 70 | 71 | 72 | org.eclipse.tycho 73 | sisu-equinox-launching 74 | ${tycho.version} 75 | 76 | 77 | org.eclipse.tycho 78 | tycho-p2-director-plugin 79 | ${tycho.version} 80 | 81 | 82 | org.eclipse.tycho 83 | tycho-core 84 | ${tycho.version} 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | org.apache.maven.wagon 93 | wagon-ssh 94 | 95 | 96 | 97 | 98 | org.apache.maven.plugins 99 | maven-release-plugin 100 | 101 | clean install 102 | 103 | 104 | 105 | org.apache.maven.plugins 106 | maven-deploy-plugin 107 | 108 | 109 | 110 | 111 | 112 | 3.0.0-SNAPSHOT 113 | 3.0 114 | 3.0 115 | 0.26.0 116 | 2.2.1 117 | 3.8.1 118 | 3.4 119 | 3.3 120 | 2.3.0.v20140506-1720 121 | [3.0.0, 4.0.0) 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/beans/product/config/ProductConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.beans.product.config; 18 | 19 | import org.wso2.maven.p2.beans.product.ConfigIni; 20 | import org.wso2.maven.p2.beans.product.Launcher; 21 | import org.wso2.maven.p2.beans.product.Plugin; 22 | import org.wso2.maven.p2.beans.product.Property; 23 | import org.wso2.maven.p2.utils.P2Constants.ProductFile; 24 | 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | import javax.xml.bind.annotation.XmlAttribute; 28 | import javax.xml.bind.annotation.XmlElement; 29 | import javax.xml.bind.annotation.XmlRootElement; 30 | import javax.xml.bind.annotation.XmlTransient; 31 | 32 | /** 33 | * Bean to represent product configurations. 34 | * 35 | * This is used to capture build-time product configuration 36 | * data from distribution pom file. 37 | * 38 | * @since 3.1.0 39 | */ 40 | @XmlRootElement 41 | public class ProductConfig { 42 | 43 | private String name = ProductFile.Product.NAME; 44 | private String uid = ProductFile.Product.UID; 45 | private String id = ProductFile.Product.ID; 46 | private String application = ProductFile.Product.APPLICATION; 47 | private String version; // If not set in project pom, carbon runtime version will be set by default. 48 | private Boolean includeLaunchers = ProductFile.Product.INCLUDE_LAUNCHERS; 49 | private ConfigIni configIni = new ConfigIni(); 50 | private Launcher launcher = new Launcher(); 51 | private List pluginConfig = this.getDefaultPluginConfig(); 52 | private List propertyConfig = this.getDefaultPropertyConfig(); 53 | 54 | public String getName() { 55 | return name; 56 | } 57 | 58 | @XmlAttribute 59 | public void setName(String name) { 60 | this.name = name; 61 | } 62 | 63 | public String getUid() { 64 | return uid; 65 | } 66 | 67 | @XmlAttribute 68 | public void setUid(String uid) { 69 | this.uid = uid; 70 | } 71 | 72 | public String getId() { 73 | return id; 74 | } 75 | 76 | @XmlAttribute 77 | public void setId(String id) { 78 | this.id = id; 79 | } 80 | 81 | public String getApplication() { 82 | return application; 83 | } 84 | 85 | @XmlAttribute 86 | public void setApplication(String application) { 87 | this.application = application; 88 | } 89 | 90 | public String getVersion() { 91 | return version; 92 | } 93 | 94 | @XmlAttribute 95 | public void setVersion(String version) { 96 | this.version = version; 97 | } 98 | 99 | public Boolean getIncludeLaunchers() { 100 | return includeLaunchers; 101 | } 102 | 103 | @XmlAttribute 104 | public void setIncludeLaunchers(Boolean includeLaunchers) { 105 | this.includeLaunchers = includeLaunchers; 106 | } 107 | 108 | public ConfigIni getConfigIni() { 109 | return configIni; 110 | } 111 | 112 | @XmlElement 113 | public void setConfigIni(ConfigIni configIni) { 114 | this.configIni = configIni; 115 | } 116 | 117 | public Launcher getLauncher() { 118 | return launcher; 119 | } 120 | 121 | @XmlElement 122 | public void setLauncher(Launcher launcher) { 123 | this.launcher = launcher; 124 | } 125 | 126 | public List getPluginConfig() { 127 | return pluginConfig; 128 | } 129 | 130 | @XmlTransient 131 | @SuppressWarnings("unused") 132 | public void setPluginConfig(List pluginConfig) { 133 | this.pluginConfig = pluginConfig; 134 | } 135 | 136 | public List getPropertyConfig() { 137 | return propertyConfig; 138 | } 139 | 140 | @XmlTransient 141 | @SuppressWarnings("unused") 142 | public void setPropertyConfig(List propertyConfig) { 143 | this.propertyConfig = propertyConfig; 144 | } 145 | 146 | private List getDefaultPropertyConfig() { 147 | List properties = new ArrayList<>(); 148 | // adding default property, value pairs 149 | properties.add(new Property("org.eclipse.update.reconcile", false)); 150 | properties.add(new Property("org.eclipse.equinox.simpleconfigurator.useReference", true)); 151 | return properties; 152 | } 153 | 154 | private List getDefaultPluginConfig() { 155 | List plugins = new ArrayList<>(); 156 | // adding default plugins wth default autoStart and startLevel configurations 157 | plugins.add(new Plugin("org.eclipse.update.configurator", true, 1)); 158 | plugins.add(new Plugin("org.eclipse.equinox.simpleconfigurator", true, 1)); 159 | plugins.add(new Plugin("org.eclipse.equinox.ds", true, 2)); 160 | plugins.add(new Plugin("org.eclipse.equinox.common", true, 2)); 161 | plugins.add(new Plugin("org.eclipse.core.runtime", true, 4)); 162 | plugins.add(new Plugin("org.eclipse.equinox.p2.reconciler.dropins", true, 4)); 163 | return plugins; 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/profile/GenerateProfileMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.maven.p2.profile; 17 | 18 | import org.apache.maven.plugin.AbstractMojo; 19 | import org.apache.maven.plugin.MojoExecutionException; 20 | import org.apache.maven.plugin.MojoFailureException; 21 | import org.apache.maven.plugins.annotations.Component; 22 | import org.apache.maven.plugins.annotations.Mojo; 23 | import org.apache.maven.plugins.annotations.Parameter; 24 | import org.apache.maven.project.MavenProject; 25 | import org.eclipse.sisu.equinox.launching.internal.P2ApplicationLauncher; 26 | import org.eclipse.tycho.model.ProductConfiguration; 27 | import org.wso2.maven.p2.beans.product.config.ProductFileConfig; 28 | import org.wso2.maven.p2.utils.FileManagementUtil; 29 | import org.wso2.maven.p2.utils.P2ApplicationLaunchManager; 30 | import org.wso2.maven.p2.utils.P2Constants; 31 | import org.wso2.maven.p2.utils.ProductFileUtils; 32 | 33 | import java.io.File; 34 | import java.io.IOException; 35 | import java.net.URL; 36 | import java.nio.file.Paths; 37 | import javax.xml.bind.JAXBException; 38 | 39 | /** 40 | * Mojo responsible for generating a runtime. 41 | * 42 | * @since 2.0.0 43 | */ 44 | @Mojo(name = "generate-runtime") 45 | public class GenerateProfileMojo extends AbstractMojo { 46 | 47 | @Parameter(required = true, defaultValue = "${project}") 48 | protected MavenProject project; 49 | /** 50 | * Metadata repository name. 51 | */ 52 | @Parameter 53 | private URL repositoryURL; 54 | 55 | /** 56 | * The product configuration, a .product file. This file manages all aspects 57 | * of a product definition from its constituent plug-ins to configuration 58 | * files to branding. 59 | */ 60 | @Parameter(defaultValue = "${productConfiguration}") 61 | private File productConfigurationFile; 62 | 63 | /** 64 | * Bean to capture build-time product file customizations 65 | * from pom level configurations. 66 | */ 67 | @Parameter 68 | private ProductFileConfig productFileConfig = new ProductFileConfig(); 69 | 70 | @Parameter 71 | private URL targetPath; 72 | 73 | /** 74 | * The new runtime to be created during p2 Director install & 75 | * the default runtime for the the application which is set in config.ini. 76 | */ 77 | @Parameter(defaultValue = "${profile}") 78 | private String runtime; 79 | 80 | 81 | @Component 82 | private P2ApplicationLauncher launcher; 83 | 84 | /** 85 | * Kill the forked test process after a certain number of seconds. If set to 0, wait forever for 86 | * the process, never timing out. 87 | */ 88 | @Parameter(defaultValue = "${p2.timeout}") 89 | private int forkedProcessTimeoutInSeconds; 90 | 91 | /** 92 | * Overridden method of AbstractMojo class. This is picked up by the maven runtime for execution. 93 | * 94 | * @throws MojoExecutionException throws when any runtime exception occurs. i.e: fail to read write file, fail to 95 | * parse a configuration xml 96 | * @throws MojoFailureException throws when the tool breaks for any configuration issues 97 | */ 98 | public void execute() throws MojoExecutionException, MojoFailureException { 99 | try { 100 | if (runtime == null) { 101 | runtime = P2Constants.DEFAULT_PROFILE_ID; 102 | } 103 | deployRepository(); 104 | //updating runtime's config.ini p2.data.area property using relative path 105 | File profileConfigIni = FileManagementUtil.getProfileConfigIniFile(targetPath.getPath(), runtime); 106 | FileManagementUtil.changeConfigIniProperty(profileConfigIni, "eclipse.p2.data.area", 107 | P2Constants.P2_DIRECTORY, this.getLog()); 108 | } catch (IOException e) { 109 | throw new MojoExecutionException(e.getMessage(), e); 110 | } 111 | } 112 | 113 | private void deployRepository() throws MojoFailureException, MojoExecutionException, IOException { 114 | ProductConfiguration productConfiguration; 115 | if (productConfigurationFile != null) { 116 | productConfiguration = ProductConfiguration.read(productConfigurationFile); 117 | } else { 118 | // going ahead with a dynamically generated product file during build-time 119 | File productFile = Paths.get(ProductFileUtils.getProductFilePath(project)).toFile(); 120 | if (!productFile.exists()) { 121 | try { 122 | ProductFileUtils.generateProductFile(productFileConfig, project); 123 | } catch (JAXBException e) { 124 | throw new MojoExecutionException("Cannot proceed as there is an error in " + 125 | "writing configurations to product file.", e); 126 | } 127 | } 128 | productConfiguration = ProductConfiguration.read(productFile); 129 | } 130 | P2ApplicationLaunchManager p2LaunchManager = new P2ApplicationLaunchManager(launcher); 131 | p2LaunchManager.setWorkingDirectory(project.getBasedir()); 132 | p2LaunchManager.setApplicationName("org.eclipse.equinox.p2.director"); 133 | p2LaunchManager.addGenerateProfileArguments(repositoryURL, productConfiguration.getId(), runtime, targetPath); 134 | p2LaunchManager.performAction(forkedProcessTimeoutInSeconds); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/feature/generate/FeatureGeneratorMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.maven.p2.feature.generate; 17 | 18 | import org.apache.maven.artifact.repository.ArtifactRepository; 19 | import org.apache.maven.plugin.AbstractMojo; 20 | import org.apache.maven.plugin.MojoExecutionException; 21 | import org.apache.maven.plugin.MojoFailureException; 22 | import org.apache.maven.plugins.annotations.Component; 23 | import org.apache.maven.plugins.annotations.LifecyclePhase; 24 | import org.apache.maven.plugins.annotations.Mojo; 25 | import org.apache.maven.plugins.annotations.Parameter; 26 | import org.apache.maven.project.MavenProject; 27 | import org.apache.maven.project.MavenProjectHelper; 28 | import org.apache.maven.repository.RepositorySystem; 29 | 30 | import java.io.File; 31 | import java.util.List; 32 | import java.util.Properties; 33 | 34 | /** 35 | * Mojo class that act as the generate maven goal. 36 | * 37 | * @since 2.0.0 38 | */ 39 | @Mojo(name = "generate", defaultPhase = LifecyclePhase.PACKAGE) 40 | public class FeatureGeneratorMojo extends AbstractMojo { 41 | 42 | @Parameter(defaultValue = "${project.artifactId}") 43 | private String id; 44 | 45 | @Parameter(defaultValue = "${project.version}") 46 | private String version; 47 | 48 | @Parameter(defaultValue = "${project.name}") 49 | private String label; 50 | 51 | @Parameter(defaultValue = "${project.description}") 52 | private String description; 53 | 54 | @Parameter(defaultValue = "%providerName") 55 | private String providerName; 56 | 57 | @Parameter(defaultValue = "%copyright") 58 | private String copyright; 59 | 60 | @Parameter(defaultValue = "%licenseURL") 61 | private String licenceUrl; 62 | 63 | @Parameter(defaultValue = "%license") 64 | private String licence; 65 | 66 | /** 67 | * Path to manifest file. 68 | */ 69 | @Parameter 70 | private File manifest; 71 | 72 | /** 73 | * Path to properties file. 74 | */ 75 | @Parameter 76 | private File propertyFile; 77 | 78 | /** 79 | * List of properties precedence over propertyFile. 80 | */ 81 | @Parameter 82 | private Properties properties; 83 | 84 | /** 85 | * Collection of bundles. 86 | */ 87 | @Parameter 88 | private List bundles; 89 | 90 | /** 91 | * Collection of required Features. 92 | */ 93 | @Parameter 94 | private List importFeatures; 95 | 96 | /** 97 | * Collection of required Features. 98 | */ 99 | @Parameter 100 | private List includeFeatures; 101 | 102 | /** 103 | * Define advice file content. 104 | */ 105 | @Parameter 106 | private List adviceFileContents; 107 | 108 | @Component 109 | private RepositorySystem repositorySystem; 110 | 111 | @Parameter(defaultValue = "${localRepository}") 112 | private ArtifactRepository localRepository; 113 | 114 | @Parameter(defaultValue = "${project.remoteArtifactRepositories}") 115 | private List remoteRepositories; 116 | 117 | @Parameter(defaultValue = "${project}") 118 | private MavenProject project; 119 | 120 | @Component 121 | private MavenProjectHelper projectHelper; 122 | 123 | /** 124 | * Overridden method of AbstractMojo class. This is picked up by the maven runtime for execution. 125 | * 126 | * @throws MojoExecutionException throws when any runtime exception occurs. i.e: fail to read write file, fail to 127 | * parse a configuration xml 128 | * @throws MojoFailureException throws when the tool breaks for any configuration issues 129 | */ 130 | public void execute() throws MojoExecutionException, MojoFailureException { 131 | FeatureGenerator featureGenerator = constructFeatureGenerator(); 132 | featureGenerator.generate(); 133 | } 134 | 135 | /** 136 | * Generates the FeatureGenerator object in order to generate the feature. 137 | * 138 | * @return FeatureGenerator 139 | */ 140 | public FeatureGenerator constructFeatureGenerator() { 141 | FeatureResourceBundle resourceBundle = new FeatureResourceBundle(); 142 | resourceBundle.setId(id); 143 | resourceBundle.setVersion(version); 144 | resourceBundle.setLabel(label); 145 | resourceBundle.setDescription(description); 146 | resourceBundle.setProviderName(providerName); 147 | resourceBundle.setCopyright(copyright); 148 | resourceBundle.setLicence(licence); 149 | resourceBundle.setLicenceUrl(licenceUrl); 150 | resourceBundle.setManifest(manifest); 151 | resourceBundle.setPropertyFile(propertyFile); 152 | resourceBundle.setProperties(properties); 153 | resourceBundle.setBundles(bundles); 154 | resourceBundle.setImportFeatures(importFeatures); 155 | resourceBundle.setIncludeFeatures(includeFeatures); 156 | resourceBundle.setAdviceFileContent(adviceFileContents); 157 | resourceBundle.setRepositorySystem(repositorySystem); 158 | resourceBundle.setLocalRepository(localRepository); 159 | resourceBundle.setRemoteRepositories(remoteRepositories); 160 | resourceBundle.setProject(project); 161 | resourceBundle.setProjectHelper(projectHelper); 162 | resourceBundle.setLog(getLog()); 163 | return new FeatureGenerator(resourceBundle); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/utils/DependencyResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.utils; 18 | 19 | import org.apache.maven.artifact.Artifact; 20 | import org.apache.maven.artifact.repository.ArtifactRepository; 21 | import org.apache.maven.model.Dependency; 22 | import org.apache.maven.model.DependencyManagement; 23 | import org.apache.maven.project.MavenProject; 24 | import org.apache.maven.repository.RepositorySystem; 25 | import org.wso2.maven.p2.beans.CarbonArtifact; 26 | 27 | import java.io.IOException; 28 | import java.util.ArrayList; 29 | import java.util.HashMap; 30 | import java.util.List; 31 | import java.util.jar.JarFile; 32 | import java.util.jar.Manifest; 33 | 34 | /** 35 | * DependencyResolver takes MavenProject object and resolve all the maven dependencies in the maven project into 36 | * internal bean representations. 37 | * 38 | * @since 2.0.0 39 | */ 40 | public class DependencyResolver { 41 | 42 | /** 43 | * Resolve the given project dependencies into CarbonArtifact objects. Dependencies are categorized into 44 | * OSGI bundles and Carbon features. 45 | * 46 | * @param project MavenProject Maven Project 47 | * @param repositorySystem RepositorySystem object 48 | * @param remoteRepositories collection of remote repositories 49 | * @param localRepository local repository representation 50 | * @return Return a {@code List>}, 1st item being {@code HashMap} containing osgi bundles specified as dependencies and 2nd item being {@code HashMap} containing carbon features specified as dependencies. 53 | * @throws IOException throws when unable to retrieve a given maven artifact 54 | */ 55 | public static List> getDependenciesForProject(MavenProject project, RepositorySystem 56 | repositorySystem, List remoteRepositories, ArtifactRepository localRepository) 57 | throws IOException { 58 | 59 | List> results = new ArrayList<>(); 60 | HashMap bundles = new HashMap<>(); 61 | HashMap features = new HashMap<>(); 62 | results.add(bundles); 63 | results.add(features); 64 | List dependencies = project.getDependencies(); 65 | 66 | DependencyManagement dependencyManagement = project.getDependencyManagement(); 67 | if (dependencyManagement != null) { 68 | dependencies.addAll(dependencyManagement.getDependencies()); 69 | } 70 | for (Dependency dependency : dependencies) { 71 | CarbonArtifact carbonArtifact = new CarbonArtifact(); 72 | carbonArtifact.setGroupId(dependency.getGroupId()); 73 | carbonArtifact.setArtifactId(dependency.getArtifactId()); 74 | carbonArtifact.setVersion(dependency.getVersion()); 75 | carbonArtifact.setType(dependency.getType()); 76 | Artifact mavenArtifact = MavenUtils.getResolvedArtifact(carbonArtifact, repositorySystem, 77 | remoteRepositories, localRepository); 78 | carbonArtifact.setArtifact(mavenArtifact); 79 | String key; 80 | if (carbonArtifact.getType().equals("jar")) { 81 | if (resolveOSGIInfo(carbonArtifact)) { 82 | key = carbonArtifact.getSymbolicName() + "_" + carbonArtifact.getBundleVersion(); 83 | bundles.put(key, carbonArtifact); 84 | } 85 | } else { 86 | key = carbonArtifact.getArtifactId() + "_" + carbonArtifact.getVersion(); 87 | features.put(key, carbonArtifact); 88 | } 89 | } 90 | return results; 91 | } 92 | 93 | /** 94 | * Resolves OSGi information for a given {@link CarbonArtifact} and populate OSGi information. 95 | * 96 | * @param artifact {@link CarbonArtifact} 97 | * @return {@code boolean} indicating whether the OSGi information is successfully resolved or not 98 | * @throws IOException if unable to retrieve the maven artifact represented by the given {@link CarbonArtifact} 99 | */ 100 | private static boolean resolveOSGIInfo(CarbonArtifact artifact) throws IOException { 101 | String bundleVersionStr = "Bundle-Version"; 102 | String bundleSymbolicNameStr = "Bundle-SymbolicName"; 103 | 104 | if (!artifact.getArtifact().getFile().exists()) { 105 | return false; 106 | } 107 | try (JarFile jarFile = new JarFile(artifact.getArtifact().getFile())) { 108 | 109 | Manifest manifest = jarFile.getManifest(); 110 | if (manifest == null) { 111 | return false; 112 | } 113 | String bundleSymbolicName = manifest.getMainAttributes().getValue(bundleSymbolicNameStr); 114 | String bundleVersion = manifest.getMainAttributes().getValue(bundleVersionStr); 115 | //Returns false if the considered .jar is not an OSGI bundle 116 | if (bundleSymbolicName == null || bundleVersion == null) { 117 | return false; 118 | } 119 | String[] split = bundleSymbolicName.split(";"); 120 | artifact.setSymbolicName(split[0]); 121 | artifact.setBundleVersion(bundleVersion); 122 | return true; 123 | } catch (IOException e) { 124 | throw new IOException("Unable to retrieve maven artifact: " + artifact.getGroupId() + 125 | ":" + artifact.getArtifactId() + ":" + artifact.getVersion(), e); 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/feature/install/FeatureInstallMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.maven.p2.feature.install; 17 | 18 | import org.apache.maven.execution.MavenSession; 19 | import org.apache.maven.plugin.AbstractMojo; 20 | import org.apache.maven.plugin.MojoExecutionException; 21 | import org.apache.maven.plugin.MojoFailureException; 22 | import org.apache.maven.plugins.annotations.Component; 23 | import org.apache.maven.plugins.annotations.LifecyclePhase; 24 | import org.apache.maven.plugins.annotations.Mojo; 25 | import org.apache.maven.plugins.annotations.Parameter; 26 | import org.apache.maven.project.MavenProject; 27 | import org.eclipse.sisu.equinox.launching.EquinoxLauncher; 28 | import org.eclipse.tycho.BuildOutputDirectory; 29 | import org.eclipse.tycho.plugins.p2.director.DirectorMojo.DirectorRuntimeType; 30 | import org.eclipse.tycho.plugins.p2.director.runtime.StandaloneDirectorRuntimeFactory; 31 | import org.wso2.maven.p2.utils.P2Constants; 32 | 33 | import java.io.File; 34 | import java.net.URL; 35 | import java.util.List; 36 | 37 | /** 38 | * Install a given set of carbon features on a product. The artifacts and metadata of the features to be installed 39 | * should reside in the repository given under {@code repositoryURL}. 40 | * 41 | * @since 2.0.0 42 | */ 43 | @Mojo(name = "install", defaultPhase = LifecyclePhase.PACKAGE) 44 | public class FeatureInstallMojo extends AbstractMojo { 45 | 46 | 47 | /** 48 | * Destination to which the features should be installed. 49 | */ 50 | @Parameter(required = true) 51 | private String destination; 52 | 53 | /** 54 | * Target runtime. 55 | */ 56 | @Parameter(required = true) 57 | private String runtime; 58 | 59 | 60 | /** 61 | * URL of the Metadata Repository. 62 | */ 63 | @Parameter 64 | private URL repositoryURL; 65 | 66 | /** 67 | * List of features. 68 | */ 69 | @Parameter(required = true) 70 | private List features; 71 | 72 | /** 73 | * Flag to indicate whether to delete old runtime files. 74 | */ 75 | @Parameter(defaultValue = "true") 76 | private boolean deleteOldRuntimeFiles = true; 77 | 78 | 79 | @Parameter(defaultValue = "${project}") 80 | private MavenProject project; 81 | 82 | @Component 83 | private EquinoxLauncher launcher; 84 | 85 | @Component 86 | private MavenSession session; 87 | 88 | @Parameter(defaultValue = "standalone") 89 | private DirectorRuntimeType directorRuntime; 90 | 91 | @Component 92 | private StandaloneDirectorRuntimeFactory standaloneDirectorFactory; 93 | 94 | /** 95 | * Kill the forked test process after a certain number of seconds. If set to 0, wait forever for 96 | * the process, never timing out. 97 | */ 98 | @Parameter(defaultValue = "${p2.timeout}") 99 | private int forkedProcessTimeoutInSeconds; 100 | 101 | private File runtimeLocation; 102 | 103 | /** 104 | * Overridden method of AbstractMojo class. This is picked up by the maven runtime for execution. 105 | * 106 | * @throws MojoExecutionException throws when any runtime exception occurs. i.e: fail to read write file, fail to 107 | * parse a configuration xml 108 | * @throws MojoFailureException throws when the tool breaks for any configuration issues 109 | */ 110 | public void execute() throws MojoExecutionException, MojoFailureException { 111 | this.runtimeLocation = new BuildOutputDirectory(this.project.getBuild().getDirectory()).getChild("director"); 112 | setDirectorRuntime(); 113 | FeatureInstaller installer = constructFeatureInstaller(); 114 | installer.install(); 115 | } 116 | 117 | /** 118 | * Constructs the FeatureInstaller object. 119 | * @return FeatureInstaller 120 | */ 121 | private FeatureInstaller constructFeatureInstaller() { 122 | FeatureInstallResourceBundle resourceBundle = new FeatureInstallResourceBundle(); 123 | resourceBundle.setDestination(this.destination); 124 | resourceBundle.setProfile(this.runtime == null ? P2Constants.DEFAULT_PROFILE_ID : this.runtime); 125 | resourceBundle.setRepository(this.repositoryURL); 126 | resourceBundle.setFeatures(this.features); 127 | resourceBundle.setDeleteOldProfileFiles(this.deleteOldRuntimeFiles); 128 | resourceBundle.setProject(this.project); 129 | resourceBundle.setLauncher(this.launcher); 130 | resourceBundle.setForkedProcessTimeoutInSeconds(this.forkedProcessTimeoutInSeconds); 131 | resourceBundle.setLog(getLog()); 132 | resourceBundle.setRuntimeLocation(this.runtimeLocation); 133 | return new FeatureInstaller(resourceBundle); 134 | } 135 | 136 | /** 137 | * Runtime in which the director application is executed. 138 | * standalone (default) - to create and use a stand-alone installation of the director application. This option is 139 | * needed if the product to be installed includes artifacts with meta-requirements (e.g. to a non-standard 140 | * touchpoint action). 141 | * 142 | * @throws MojoFailureException 143 | * @throws MojoExecutionException 144 | */ 145 | private void setDirectorRuntime() throws MojoFailureException, MojoExecutionException { 146 | switch (directorRuntime) { 147 | case standalone: 148 | standaloneDirectorFactory.createStandaloneDirector(this.runtimeLocation, 149 | this.session.getLocalRepository(), this.forkedProcessTimeoutInSeconds); 150 | return; 151 | default: 152 | throw new MojoFailureException("Unsupported value for attribute 'directorRuntime': \"" + 153 | directorRuntime + "\""); 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/utils/BundleUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.utils; 18 | 19 | import java.util.regex.Matcher; 20 | import java.util.regex.Pattern; 21 | 22 | /** 23 | * Utility class composed of utility methods pertaining to a Bundles. 24 | * 25 | * @since 2.0.0 26 | */ 27 | public class BundleUtils { 28 | 29 | private static final Pattern OSGI_VERSION_PATTERN = Pattern.compile("[0-9]+\\.[0-9]+\\.[0-9]+(\\.[0-9A-Za-z_-]+)?"); 30 | private static final Pattern ONLY_NUMBERS = Pattern.compile("[0-9]+"); 31 | 32 | /** 33 | * Returns the OSGI version for the given artifact version. 34 | * 35 | * @param version artifact version 36 | * @return OSGI version 37 | */ 38 | public static String getOSGIVersion(String version) { 39 | // This method is taken from org.apache.maven.shared.osgi.DefaultMaven2OsgiConverter to get the OSGI version 40 | // from a give version artifact version. 41 | String osgiVersion; 42 | 43 | // Matcher m = P_VERSION.matcher(version); 44 | // if (m.matches()) { 45 | // osgiVersion = m.group(1) + "." + m.group(3); 46 | // } 47 | 48 | /* TODO need a regexp guru here */ 49 | 50 | Matcher m; 51 | 52 | /* if it's already OSGi compliant don't touch it */ 53 | m = OSGI_VERSION_PATTERN.matcher(version); 54 | if (m.matches()) { 55 | return version; 56 | } 57 | 58 | osgiVersion = version; 59 | 60 | /* check for dated snapshot versions with only major or major and minor */ 61 | Pattern datedSnapshotPattern = 62 | Pattern.compile("([0-9])(\\.([0-9]))?(\\.([0-9]))?\\-([0-9]{8}\\.[0-9]{6}\\-[0-9]*)"); 63 | m = datedSnapshotPattern.matcher(osgiVersion); 64 | if (m.matches()) { 65 | String major = m.group(1); 66 | String minor = (m.group(3) != null) ? m.group(3) : "0"; 67 | String service = (m.group(5) != null) ? m.group(5) : "0"; 68 | String qualifier = m.group(6).replaceAll("-", "_").replaceAll("\\.", "_"); 69 | osgiVersion = major + "." + minor + "." + service + "." + qualifier; 70 | } 71 | 72 | /* else transform first - to . and others to _ */ 73 | osgiVersion = osgiVersion.replaceFirst("-", "\\."); 74 | osgiVersion = osgiVersion.replaceAll("-", "_"); 75 | m = OSGI_VERSION_PATTERN.matcher(osgiVersion); 76 | if (m.matches()) { 77 | return osgiVersion; 78 | } 79 | 80 | /* remove dots in the middle of the qualifier */ 81 | Pattern dotsInQualifierPattern = Pattern.compile("([0-9])(\\.[0-9])?\\.([0-9A-Za-z_-]+)\\.([0-9A-Za-z_-]+)"); 82 | m = dotsInQualifierPattern.matcher(osgiVersion); 83 | if (m.matches()) { 84 | String s1 = m.group(1); 85 | String s2 = m.group(2); 86 | String s3 = m.group(3); 87 | String s4 = m.group(4); 88 | 89 | Matcher qualifierMatcher = ONLY_NUMBERS.matcher(s3); 90 | /* 91 | * if last portion before dot is only numbers then it's not in the middle of the 92 | * qualifier 93 | */ 94 | if (!qualifierMatcher.matches()) { 95 | osgiVersion = s1 + s2 + "." + s3 + "_" + s4; 96 | } 97 | } 98 | 99 | /* convert 100 | * 1.string -> 1.0.0.string 101 | * 1.2.string -> 1.2.0.string 102 | * 1 -> 1.0.0 103 | * 1.1 -> 1.1.0 104 | */ 105 | //Pattern NEED_TO_FILL_ZEROS = Pattern.compile( "([0-9])(\\.([0-9]))?\\.([0-9A-Za-z_-]+)" ); 106 | Pattern needToFillZerosPattern = Pattern.compile("([0-9])(\\.([0-9]))?(\\.([0-9A-Za-z_-]+))?"); 107 | m = needToFillZerosPattern.matcher(osgiVersion); 108 | if (m.matches()) { 109 | String major = m.group(1); 110 | String minor = m.group(3); 111 | String service = null; 112 | String qualifier = m.group(5); 113 | 114 | /* if there's no qualifier just fill with 0s */ 115 | if (qualifier == null) { 116 | osgiVersion = getOSGIVersion(major, minor, null, null); 117 | } else { 118 | /* if last portion is only numbers then it's not a qualifier */ 119 | Matcher qualifierMatcher = ONLY_NUMBERS.matcher(qualifier); 120 | if (qualifierMatcher.matches()) { 121 | if (minor == null) { 122 | minor = qualifier; 123 | } else { 124 | service = qualifier; 125 | } 126 | osgiVersion = getOSGIVersion(major, minor, service, null); 127 | } else { 128 | osgiVersion = getOSGIVersion(major, minor, null, qualifier); 129 | } 130 | } 131 | } 132 | 133 | m = OSGI_VERSION_PATTERN.matcher(osgiVersion); 134 | /* if still its not OSGi version then add everything as qualifier */ 135 | if (!m.matches()) { 136 | String major = "0"; 137 | String minor = "0"; 138 | String service = "0"; 139 | String qualifier = osgiVersion.replaceAll("\\.", "_"); 140 | osgiVersion = major + "." + minor + "." + service + "." + qualifier; 141 | } 142 | 143 | return osgiVersion; 144 | } 145 | 146 | private static String getOSGIVersion(String major, String minor, String service, String qualifier) { 147 | StringBuilder sb = new StringBuilder(); 148 | sb.append(major != null ? major : "0"); 149 | sb.append('.'); 150 | sb.append(minor != null ? minor : "0"); 151 | sb.append('.'); 152 | sb.append(service != null ? service : "0"); 153 | if (qualifier != null) { 154 | sb.append('.'); 155 | sb.append(qualifier); 156 | } 157 | return sb.toString(); 158 | } 159 | 160 | } 161 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/feature/install/FeatureInstallResourceBundle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.feature.install; 18 | 19 | import org.apache.maven.plugin.logging.Log; 20 | import org.apache.maven.project.MavenProject; 21 | import org.eclipse.sisu.equinox.launching.EquinoxLauncher; 22 | 23 | import java.io.File; 24 | import java.net.URL; 25 | import java.util.List; 26 | 27 | /** 28 | * Bean class containing all the parameters entered to the mojo through plugin configuration. 29 | *

30 | * The purpose of this class is to make any configuration property accessible from any class by simply passing this 31 | * bean as a parameter. 32 | * 33 | * @since 2.0.0 34 | */ 35 | public class FeatureInstallResourceBundle { 36 | 37 | private String destination; 38 | private String profile; 39 | private URL repository; 40 | private List features; 41 | private boolean deleteOldProfileFiles; 42 | private MavenProject project; 43 | private EquinoxLauncher launcher; 44 | private File runtimeLocation; 45 | private int forkedProcessTimeoutInSeconds; 46 | private Log log; 47 | 48 | /** 49 | * Returns the destination of the profile to install features. 50 | * 51 | * @return {@code String} 52 | */ 53 | public String getDestination() { 54 | return destination; 55 | } 56 | 57 | /** 58 | * Sets the destination of the profile to install features. 59 | * 60 | * @param destination {@code String} 61 | */ 62 | public void setDestination(String destination) { 63 | this.destination = destination; 64 | } 65 | 66 | /** 67 | * Returns the name of the profile that the features will be installed. 68 | * 69 | * @return {@code String} 70 | */ 71 | public String getProfile() { 72 | return profile; 73 | } 74 | 75 | /** 76 | * Sets the name of the profile that the features will be installed. 77 | * 78 | * @param profile {@code String} 79 | */ 80 | public void setProfile(String profile) { 81 | this.profile = profile; 82 | } 83 | 84 | /** 85 | * Returns the repository url where the features taken from. 86 | * 87 | * @return {@link URL} 88 | */ 89 | public URL getRepository() { 90 | return repository; 91 | } 92 | 93 | /** 94 | * Sets the repository url where the features taken from. 95 | * 96 | * @param repository {@link URL} 97 | */ 98 | public void setRepository(URL repository) { 99 | this.repository = repository; 100 | } 101 | 102 | /** 103 | * Returns the features list to be installed. 104 | * 105 | * @return {@code List} 106 | */ 107 | public List getFeatures() { 108 | return features; 109 | } 110 | 111 | /** 112 | * Sets the features list to be installed. 113 | * 114 | * @param features {@code List} 115 | */ 116 | public void setFeatures(List features) { 117 | this.features = features; 118 | } 119 | 120 | /** 121 | * Returns a boolean which specifies whether the old profile files should be deleted or not. 122 | * 123 | * @return {@code boolean} 124 | */ 125 | public boolean isDeleteOldProfileFiles() { 126 | return deleteOldProfileFiles; 127 | } 128 | 129 | /** 130 | * Specify whether old profile files should be deleted or not. 131 | * 132 | * @param deleteOldProfileFiles {@code boolean} 133 | */ 134 | public void setDeleteOldProfileFiles(boolean deleteOldProfileFiles) { 135 | this.deleteOldProfileFiles = deleteOldProfileFiles; 136 | } 137 | 138 | /** 139 | * Returns the maven project injected by the maven runtime. 140 | * 141 | * @return {@link MavenProject} 142 | */ 143 | public MavenProject getProject() { 144 | return project; 145 | } 146 | 147 | /** 148 | * Sets the maven project injected by the maven runtime. 149 | * 150 | * @param project {@link MavenProject} 151 | */ 152 | public void setProject(MavenProject project) { 153 | this.project = project; 154 | } 155 | 156 | /** 157 | * Returns the EquinoxLauncher injected by the maven runtime. 158 | * 159 | * @return {@link EquinoxLauncher} 160 | */ 161 | public EquinoxLauncher getLauncher() { 162 | return launcher; 163 | } 164 | 165 | /** 166 | * Sets the EquinoxLauncher injected by the maven runtime. 167 | * 168 | * @param launcher {@link EquinoxLauncher} 169 | */ 170 | public void setLauncher(EquinoxLauncher launcher) { 171 | this.launcher = launcher; 172 | } 173 | 174 | /** 175 | * Returns the forkedProcessTimeout in seconds. 176 | * @return {@code int} 177 | */ 178 | public int getForkedProcessTimeoutInSeconds() { 179 | return forkedProcessTimeoutInSeconds; 180 | } 181 | 182 | /** 183 | * Sets the forkedProcessTimeout in seconds. 184 | * @param forkedProcessTimeoutInSeconds {@code int} 185 | */ 186 | public void setForkedProcessTimeoutInSeconds(int forkedProcessTimeoutInSeconds) { 187 | this.forkedProcessTimeoutInSeconds = forkedProcessTimeoutInSeconds; 188 | } 189 | 190 | /** 191 | * Returns the Log. 192 | * 193 | * @return {@link Log} 194 | */ 195 | public Log getLog() { 196 | return log; 197 | } 198 | 199 | /** 200 | * Sets the Log. 201 | * 202 | * @param log {@link Log} 203 | */ 204 | public void setLog(Log log) { 205 | this.log = log; 206 | } 207 | 208 | /** 209 | * Returns the Runtime Location. 210 | * 211 | * @return {@link File} 212 | */ 213 | public File getRuntimeLocation() { 214 | return runtimeLocation; 215 | } 216 | 217 | /** 218 | * Sets the Runtime Location. 219 | * 220 | * @param runtimeLocation {@link File} 221 | */ 222 | public void setRuntimeLocation(File runtimeLocation) { 223 | this.runtimeLocation = runtimeLocation; 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/beans/CarbonArtifact.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.beans; 18 | 19 | import org.apache.maven.artifact.Artifact; 20 | 21 | /** 22 | * Bean class representing CarbonArtifacts. 23 | *

24 | * This class is extended by all the Bean classes which represent any artifact created from the carbon feature plugin. 25 | *

26 | * 27 | * @since 2.0.0 28 | */ 29 | public class CarbonArtifact { 30 | private String groupId; 31 | private String artifactId; 32 | private String version; 33 | private String symbolicName; 34 | private String type; 35 | private String bundleVersion; 36 | private Artifact artifact; 37 | private String compatibility = "compatible"; 38 | 39 | /** 40 | * Returns the maven group id for the carbon artifact. 41 | * 42 | * @return String 43 | */ 44 | public String getGroupId() { 45 | return groupId; 46 | } 47 | 48 | /** 49 | * Sets the maven group id for the carbon artifact. 50 | * 51 | * @param groupId String 52 | */ 53 | public void setGroupId(String groupId) { 54 | this.groupId = groupId; 55 | } 56 | 57 | /** 58 | * Returns the maven artifact id for the carbon artifact. 59 | * 60 | * @return String 61 | */ 62 | public String getArtifactId() { 63 | return artifactId; 64 | } 65 | 66 | /** 67 | * Sets the maven artifact id for the carbon artifact. 68 | * 69 | * @param artifactId String 70 | */ 71 | public void setArtifactId(String artifactId) { 72 | this.artifactId = artifactId; 73 | } 74 | 75 | /** 76 | * Returns the maven version for this artifact. 77 | *

78 | * Important: This is not the OSGI version 79 | *

80 | * 81 | * @return String 82 | */ 83 | public String getVersion() { 84 | return version; 85 | } 86 | 87 | /** 88 | * Sets the maven version for this artifact. 89 | *

90 | * Important: This is not the OSGI version 91 | *

92 | * 93 | * @param version String 94 | */ 95 | public void setVersion(String version) { 96 | this.version = version; 97 | } 98 | 99 | /** 100 | * Returns the actual maven artifact represented by this carbon artifact. 101 | * 102 | * @return org.apache.maven.artifact object 103 | */ 104 | public Artifact getArtifact() { 105 | return artifact; 106 | } 107 | 108 | /** 109 | * Sets the actual maven artifact represented by this carbon artifact. 110 | * 111 | * @param artifact org.apache.maven.artifact object 112 | */ 113 | public void setArtifact(Artifact artifact) { 114 | this.artifact = artifact; 115 | } 116 | 117 | /** 118 | * Returns the OSGI symbolic name which is in the manifest file of the artifact represented by this 119 | * carbon artifact. This is applicable only if the represented carbon artifact is an OSGI bundle. 120 | * 121 | * @return String symbolic name 122 | */ 123 | public String getSymbolicName() { 124 | return symbolicName; 125 | } 126 | 127 | /** 128 | * Sets the OSGI symbolic name which is in the manifest file of the artifact represented by this 129 | * carbon artifact. This is applicable only if the represented carbon artifact is an OSGI bundle. 130 | * 131 | * @param symbolicName String 132 | */ 133 | public void setSymbolicName(String symbolicName) { 134 | this.symbolicName = symbolicName; 135 | } 136 | 137 | /** 138 | * Returns the file type of the actual artifact represented by this carbon artifact. 139 | * i.e: Jar, Zip 140 | * 141 | * @return String file extension 142 | */ 143 | public String getType() { 144 | return type; 145 | } 146 | 147 | /** 148 | * Sets the file type(extension) of the actual artifact represented by this carbon artifact. 149 | * 150 | * @param type String 151 | */ 152 | public void setType(String type) { 153 | this.type = type; 154 | } 155 | 156 | /** 157 | * Returns the OSGI bundle version of the actual artifact represented by this carbon artifact. 158 | * This is applicable only if the carbon artifact represent an OSGI bundle. 159 | * 160 | * @return String 161 | */ 162 | public String getBundleVersion() { 163 | return bundleVersion; 164 | } 165 | 166 | /** 167 | * Sets the OSGI bundle version of the actual artifact represented by this carbon artifact. 168 | * This is applicable only if the carbon artifact represent an OSGI bundle. 169 | * 170 | * @param bundleVersion String 171 | */ 172 | public void setBundleVersion(String bundleVersion) { 173 | this.bundleVersion = bundleVersion; 174 | } 175 | 176 | /** 177 | * Returns the compatibility type of this CarbonArtifact. 178 | * Permitted values are; 179 | *
    180 | *
  • perfect
  • 181 | *
  • equivalent
  • 182 | *
  • compatible
  • 183 | *
  • greaterOrEqual
  • 184 | *
  • patch
  • 185 | *
  • optional
  • 186 | *
187 | * 188 | * @return String compatibility 189 | */ 190 | public String getCompatibility() { 191 | return compatibility; 192 | } 193 | 194 | /* 195 | * Though there is no usage for this method from the code, do not delete this as this is used by maven 196 | * context to inject match. 197 | * 198 | */ 199 | public void setCompatibility(String compatibility) { 200 | this.compatibility = compatibility; 201 | } 202 | 203 | /** 204 | * Util method which will copy some of the properties of this parent class into it's sub classes. 205 | * 206 | * @param item target Subclass of CarbonArtifact object which needs to copy fields of this object. 207 | * @param SubClass of CarbonArtifact 208 | */ 209 | public void copyTo(T item) { 210 | item.setArtifact(this.artifact); 211 | item.setVersion(this.version); 212 | item.setArtifactId(this.artifactId); 213 | item.setBundleVersion(this.bundleVersion); 214 | item.setGroupId(this.groupId); 215 | item.setSymbolicName(this.symbolicName); 216 | item.setType(this.type); 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/utils/ProductFileUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.utils; 18 | 19 | import org.apache.maven.artifact.Artifact; 20 | import org.apache.maven.plugin.MojoExecutionException; 21 | import org.apache.maven.project.MavenProject; 22 | import org.wso2.maven.p2.beans.product.Configurations; 23 | import org.wso2.maven.p2.beans.product.Product; 24 | import org.wso2.maven.p2.beans.product.config.ProductConfig; 25 | import org.wso2.maven.p2.beans.product.config.ProductFileConfig; 26 | 27 | import java.io.File; 28 | import java.io.IOException; 29 | import java.io.StringWriter; 30 | import java.nio.charset.Charset; 31 | import java.nio.file.Files; 32 | import java.nio.file.Paths; 33 | import javax.xml.bind.JAXBContext; 34 | import javax.xml.bind.JAXBException; 35 | import javax.xml.bind.Marshaller; 36 | 37 | /** 38 | * Utility class for helper functions in generating and reading a product file at build-time. 39 | * 40 | * This class is to be used by publish-product and generate-runtime maven goals. 41 | * 42 | * @since 3.1.0 43 | */ 44 | public class ProductFileUtils { 45 | 46 | /** 47 | * Write Product bean as an XML to a product file. 48 | * 49 | * @param productFileConfig productFileConfig bean as read from project pom. 50 | * @param mavenProject mavenProject bean as read from project pom. 51 | * @throws JAXBException Is thrown if an error occurs in writing configurations into a string. 52 | * @throws MojoExecutionException Is thrown if maven project is not been able to be read. 53 | * @throws IOException Is thrown if an error occurs in writing configurations into a product file. 54 | */ 55 | public static void generateProductFile(ProductFileConfig productFileConfig, MavenProject mavenProject) throws 56 | JAXBException, MojoExecutionException, IOException { 57 | // validating version and featureConfig values captured from project pom 58 | ProductConfig validatedProductConfig = ProductFileUtils.validateProductConfig(productFileConfig. 59 | getProductConfig(), mavenProject); 60 | 61 | // populating a product instance with validated values for writing to a product file 62 | Product product = new Product(); 63 | 64 | product.setName(validatedProductConfig.getName()); 65 | product.setUid(validatedProductConfig.getUid()); 66 | product.setId(validatedProductConfig.getId()); 67 | product.setApplication(validatedProductConfig.getApplication()); 68 | product.setVersion(validateProductVersion(validatedProductConfig.getVersion())); 69 | product.setIncludeLaunchers(validatedProductConfig.getIncludeLaunchers()); 70 | product.setConfigIni(validatedProductConfig.getConfigIni()); 71 | product.setLauncher(validatedProductConfig.getLauncher()); 72 | product.setConfigurations(new Configurations(validatedProductConfig.getPluginConfig(), validatedProductConfig 73 | .getPropertyConfig())); 74 | 75 | // writing to a product file 76 | StringWriter stringWriter = new StringWriter(); 77 | stringWriter.append("").append(System 79 | .lineSeparator()).append("").append(System.lineSeparator()); 81 | 82 | JAXBContext jaxbContext = JAXBContext.newInstance(Product.class); 83 | Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); 84 | 85 | jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); 86 | jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 87 | jaxbMarshaller.marshal(product, stringWriter); 88 | 89 | Files.write(Paths.get(ProductFileUtils.getProductFilePath(mavenProject)), stringWriter.toString() 90 | .getBytes(Charset.forName(P2Constants.DEFAULT_ENCODING))); 91 | } 92 | 93 | /** 94 | * Get path to dynamically generated product file. 95 | * 96 | * @param mavenProject bean as read from project pom. 97 | * @return String Path to dynamically generated product file. 98 | * @throws MojoExecutionException Is thrown if maven project is not been able to be read. 99 | */ 100 | public static String getProductFilePath(MavenProject mavenProject) throws MojoExecutionException { 101 | if (mavenProject == null) { 102 | throw new MojoExecutionException("Unable to read maven project for finding project path."); 103 | } else { 104 | return mavenProject.getBasedir().getAbsolutePath() + File.separator + P2Constants.ProductFile 105 | .TARGET_DIRECTORY + File.separator + P2Constants.ProductFile.NAME; 106 | } 107 | } 108 | 109 | private static ProductConfig validateProductConfig(ProductConfig productConfig, MavenProject mavenProject) throws 110 | MojoExecutionException { 111 | if (productConfig.getVersion() == null) { 112 | productConfig.setVersion(ProductFileUtils.getDependencyVersion(mavenProject, P2Constants.ProductFile 113 | .Product.OSGI_RUNTIME_FEATURE)); 114 | } 115 | return productConfig; 116 | } 117 | 118 | private static String validateProductVersion(String version) { 119 | if (version != null && !version.isEmpty() && version.contains(P2Constants.ProductFile.Feature 120 | .VERSION_CHAR_REPLACED)) { 121 | version = version.replaceAll(P2Constants.ProductFile.Feature.VERSION_CHAR_REPLACED, P2Constants 122 | .ProductFile.Feature.VERSION_CHAR_REPLACEMENT); 123 | } 124 | return version; 125 | } 126 | 127 | private static String getDependencyVersion(MavenProject mavenProject, String dependency) throws 128 | MojoExecutionException { 129 | if (mavenProject == null) { 130 | throw new MojoExecutionException("Unable to read maven project for finding dependencies."); 131 | } else if (dependency == null || dependency.isEmpty()) { 132 | throw new MojoExecutionException("Unable to find version for invalid dependency value."); 133 | } else { 134 | Artifact selectedArtifact = mavenProject.getDependencyArtifacts() 135 | .stream() 136 | .filter(artifact -> artifact.getArtifactId().contains(dependency)) 137 | .findFirst() 138 | .orElseThrow(() -> new MojoExecutionException("Unable to find version as there seems to be " + 139 | "no pom based configuration for the provided dependency.")); 140 | 141 | String dependencyVersion = selectedArtifact.getBaseVersion(); 142 | if (dependencyVersion == null || dependencyVersion.isEmpty()) { 143 | throw new MojoExecutionException("Unable to find version for the provided dependency."); 144 | } 145 | return dependencyVersion; 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/feature/install/FeatureInstaller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.feature.install; 18 | 19 | import org.apache.maven.plugin.MojoExecutionException; 20 | import org.apache.maven.plugin.MojoFailureException; 21 | import org.apache.maven.plugin.logging.Log; 22 | import org.wso2.maven.p2.utils.FileManagementUtil; 23 | import org.wso2.maven.p2.utils.P2Constants; 24 | import org.wso2.maven.p2.utils.StandaloneManager; 25 | 26 | import java.io.File; 27 | import java.io.FileOutputStream; 28 | import java.io.IOException; 29 | import java.io.OutputStreamWriter; 30 | import java.io.PrintWriter; 31 | import java.io.Writer; 32 | import java.nio.file.Paths; 33 | 34 | /** 35 | * FeatureInstaller takes parameters from the pom.xml and generates the profile. 36 | * 37 | * @since 2.0.0 38 | */ 39 | public class FeatureInstaller { 40 | 41 | private final FeatureInstallResourceBundle resourceBundle; 42 | private final String destination; 43 | 44 | private Log log; 45 | 46 | /** 47 | * ProfileGenerator constructor taking ProfileResourceBundle as a parameter. 48 | * 49 | * @param resourceBundle ProfileResourceBundle 50 | */ 51 | public FeatureInstaller(FeatureInstallResourceBundle resourceBundle) { 52 | this.resourceBundle = resourceBundle; 53 | this.log = resourceBundle.getLog(); 54 | this.destination = resourceBundle.getDestination(); 55 | } 56 | 57 | /** 58 | * Performs the installation operation. 59 | * 60 | * @throws MojoExecutionException throws when any runtime exception occurs. i.e: fail to read write file, fail to 61 | * install any given feature. 62 | * @throws MojoFailureException throws when the tool breaks for any configuration issues 63 | */ 64 | public void install() throws MojoExecutionException, MojoFailureException { 65 | try { 66 | writeEclipseIni(); 67 | installFeatures(); 68 | updateProfileConfigIni(); 69 | deleteOldProfiles(); 70 | } catch (IOException e) { 71 | throw new MojoExecutionException(e.getMessage(), e); 72 | } 73 | } 74 | 75 | /** 76 | * Updating profile's config.ini p2.data.area property using relative path. 77 | */ 78 | private void updateProfileConfigIni() { 79 | File profileConfigIni = FileManagementUtil.getProfileConfigIniFile(destination, resourceBundle.getProfile()); 80 | FileManagementUtil.changeConfigIniProperty(profileConfigIni, "eclipse.p2.data.area", P2Constants.P2_DIRECTORY, 81 | resourceBundle.getLog()); 82 | } 83 | 84 | /** 85 | * Calls the P2ApplicationLauncher and install the features. 86 | * 87 | * @throws MojoFailureException throws when the director application fail to install any given feature. 88 | */ 89 | private void installFeatures() throws MojoFailureException { 90 | this.log.info("Running Equinox P2 Director Application"); 91 | StandaloneManager launcher = new StandaloneManager(resourceBundle.getLauncher()); 92 | launcher.setRuntimeLocation(resourceBundle.getRuntimeLocation()); 93 | launcher.addArgumentsToInstallFeatures(resourceBundle.getRepository().toExternalForm(), destination, 94 | resourceBundle.getProfile()); 95 | launcher.performAction(extractIUsToInstall(), resourceBundle.getForkedProcessTimeoutInSeconds()); 96 | } 97 | 98 | /** 99 | * Generate the formatted string representation of features from the features passed in through the pom.xml. This 100 | * formatted string is passed into P2ApplicationLauncher to generate the profile. 101 | * 102 | * @return formatted string to pass into P2ApplicationLauncher 103 | */ 104 | private String extractIUsToInstall() { 105 | StringBuilder installIUs = new StringBuilder(); 106 | resourceBundle.getFeatures().forEach(feature -> 107 | installIUs.append(feature.getId().trim()).append("/").append(feature.getVersion().trim()).append(",")); 108 | 109 | return installIUs.toString(); 110 | } 111 | 112 | /** 113 | * Delete old profile files located at ${destination}/p2/org.eclipse.equinox.p2.engine/profileRegistry. 114 | * 115 | * @throws IOException throws when fail to delete old profile files 116 | */ 117 | private void deleteOldProfiles() throws IOException { 118 | //In not specified to delete, then return the method. 119 | if (!resourceBundle.isDeleteOldProfileFiles()) { 120 | return; 121 | } 122 | String destination = resourceBundle.getDestination(); 123 | if (!destination.endsWith("/")) { 124 | destination = destination + "/"; 125 | resourceBundle.setDestination(destination); 126 | } 127 | String profileFolderName = resourceBundle.getDestination() + 128 | "p2/org.eclipse.equinox.p2.engine/profileRegistry/" + resourceBundle.getProfile() + ".profile"; 129 | 130 | File profileFolder = new File(profileFolderName); 131 | if (profileFolder.isDirectory()) { 132 | String[] profileFileList = profileFolder.list((dir, name) -> name.endsWith(".profile")); 133 | 134 | //deleting old profile files 135 | if (profileFileList != null) { 136 | for (int i = 0; i < (profileFileList.length - 1); i++) { 137 | File profileFile = new File(profileFolderName, profileFileList[i]); 138 | if (profileFile.exists() && !profileFile.delete()) { 139 | throw new IOException("Failed to delete old profile file: " + 140 | profileFile.getAbsolutePath()); 141 | } 142 | } 143 | } 144 | 145 | } 146 | } 147 | 148 | /** 149 | * Truncate and write the eclipse.ini file with the new profile location. 150 | * 151 | * @throws IOException throws when fail to eclipse.ini file/fail to delete old files. 152 | */ 153 | private void writeEclipseIni() throws IOException { 154 | String profileLocation = resourceBundle.getDestination() + File.separator + resourceBundle.getProfile(); 155 | 156 | File eclipseIni = Paths.get(profileLocation, "eclipse.ini").toFile(); 157 | if (eclipseIni.exists()) { 158 | updateFile(eclipseIni, profileLocation); 159 | } 160 | } 161 | 162 | /** 163 | * Update eclipse.ini. 164 | * 165 | * @param file File object 166 | * @param profileLocation location of the profile directory 167 | * @throws IOException throws if fail to update the file 168 | */ 169 | private void updateFile(File file, String profileLocation) throws IOException { 170 | if (file.exists()) { 171 | if (!file.delete()) { 172 | throw new IOException("Failed to delete " + file.getAbsolutePath()); 173 | } 174 | } 175 | this.log.info("Updating " + file.getName()); 176 | try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), P2Constants.DEFAULT_ENCODING); 177 | PrintWriter pw = new PrintWriter(writer)) { 178 | pw.write("-install\n"); 179 | pw.write(profileLocation); 180 | pw.flush(); 181 | } catch (IOException e) { 182 | this.log.debug("Error while writing to file " + file.getName(), e); 183 | } 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/utils/P2Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.maven.p2.utils; 17 | 18 | import org.apache.maven.plugin.MojoExecutionException; 19 | import org.apache.maven.project.MavenProject; 20 | import org.w3c.dom.Document; 21 | import org.w3c.dom.Element; 22 | import org.wso2.maven.p2.repository.CatFeature; 23 | import org.wso2.maven.p2.repository.Category; 24 | 25 | import java.io.BufferedReader; 26 | import java.io.File; 27 | import java.io.FileInputStream; 28 | import java.io.IOException; 29 | import java.io.InputStreamReader; 30 | import java.util.ArrayList; 31 | import java.util.HashMap; 32 | import java.util.List; 33 | import java.util.Map; 34 | import java.util.regex.Pattern; 35 | import javax.xml.parsers.DocumentBuilder; 36 | import javax.xml.parsers.DocumentBuilderFactory; 37 | import javax.xml.parsers.ParserConfigurationException; 38 | import javax.xml.transform.OutputKeys; 39 | import javax.xml.transform.Transformer; 40 | import javax.xml.transform.TransformerConfigurationException; 41 | import javax.xml.transform.TransformerException; 42 | import javax.xml.transform.TransformerFactory; 43 | import javax.xml.transform.dom.DOMSource; 44 | import javax.xml.transform.stream.StreamResult; 45 | 46 | 47 | /** 48 | * The class contains operations related to Categories, which is out of the scope for current set of tasks. Thus 49 | * the refactoring is done for a minimum for the moment. 50 | * 51 | * @since 2.0.0 52 | */ 53 | public class P2Utils { 54 | private static String[] matchList = new String[]{"perfect", "equivalent", "compatible", "greaterOrEqual", "patch", 55 | "optional"}; 56 | 57 | /** 58 | * Traverse the given p2Inf file, find the last index of the property entries in the file and returns. This us 59 | * used when updating the p2inf with new properties. 60 | * 61 | * @param p2InfFile p2Inf Flie object 62 | * @return last index of the properties 63 | * @throws IOException throws if unable to read the p2Inf file 64 | */ 65 | public static int getLastIndexOfProperties(File p2InfFile) throws IOException { 66 | int min = -1; 67 | if (p2InfFile.exists()) { 68 | 69 | try (InputStreamReader reader = new InputStreamReader(new FileInputStream(p2InfFile), 70 | P2Constants.DEFAULT_ENCODING); 71 | BufferedReader in = new BufferedReader(reader)) { 72 | String line; 73 | while ((line = in.readLine()) != null) { 74 | String[] split = line.split("="); 75 | String[] split2 = split[0].split(Pattern.quote(".")); 76 | if (split2[0].equalsIgnoreCase("properties")) { 77 | int index = Integer.parseInt(split2[1]); 78 | if (index > min) { 79 | min = index; 80 | } 81 | } 82 | } 83 | } 84 | } 85 | return min; 86 | } 87 | 88 | public static boolean isMatchString(String matchStr) { 89 | for (String match : matchList) { 90 | if (matchStr.equalsIgnoreCase(match)) { 91 | return true; 92 | } 93 | } 94 | return false; 95 | } 96 | 97 | /** 98 | * Takes a match string and returns the correct matching string correspond to it. 99 | * 100 | * @param matchStr matching string 101 | * @return the correct matching rule corresponds to the given matching string 102 | */ 103 | public static String getMatchRule(String matchStr) { 104 | if (isPatch(matchStr)) { 105 | return "perfect"; 106 | } 107 | for (String match : matchList) { 108 | if (matchStr.equalsIgnoreCase(match)) { 109 | return match; 110 | } 111 | } 112 | return null; 113 | } 114 | 115 | /** 116 | * Returns whether the given matching string matches the patch matching rule. 117 | * 118 | * @param matchStr matching string to check 119 | * @return whether the given matching rule matches with patch matching rule 120 | */ 121 | public static boolean isPatch(String matchStr) { 122 | return matchStr.equalsIgnoreCase("patch"); 123 | } 124 | 125 | /** 126 | * Create the category file. 127 | * 128 | * @param project Maven project 129 | * @param categories categories list 130 | * @param categoryFile category file 131 | * @throws ParserConfigurationException throws if fail to generate a manifest document 132 | * @throws TransformerException throws when fail to transform the category file 133 | * @throws MojoExecutionException throws if fail to process features 134 | */ 135 | public static void createCategoryFile(MavenProject project, List categories, File categoryFile) 136 | throws ParserConfigurationException, TransformerException, MojoExecutionException { 137 | 138 | Map featureCategories = new HashMap(); 139 | 140 | Document doc = getManifestDocument(); 141 | Element rootElement = doc.getDocumentElement(); 142 | 143 | if (rootElement == null) { 144 | rootElement = doc.createElement("site"); 145 | doc.appendChild(rootElement); 146 | } 147 | 148 | for (Object object : categories) { 149 | if (object instanceof Category) { 150 | Category cat = (Category) object; 151 | Element categoryDef = doc.createElement("category-def"); 152 | categoryDef.setAttribute("name", cat.getId()); 153 | categoryDef.setAttribute("label", cat.getLabel()); 154 | rootElement.appendChild(categoryDef); 155 | Element descriptionElement = doc.createElement("description"); 156 | descriptionElement.setTextContent(cat.getDescription()); 157 | categoryDef.appendChild(descriptionElement); 158 | ArrayList processedFeatures = cat.getProcessedFeatures(project); 159 | for (CatFeature feature : processedFeatures) { 160 | if (!featureCategories.containsKey(feature.getId() + feature.getVersion())) { 161 | ArrayList list = new ArrayList(); 162 | featureCategories.put((feature.getId() + feature.getVersion()), list); 163 | list.add(feature); 164 | } 165 | ArrayList list = (ArrayList) featureCategories.get(feature.getId() + feature.getVersion()); 166 | list.add(cat.getId()); 167 | } 168 | } 169 | } 170 | 171 | for (Object object : featureCategories.entrySet()) { 172 | if (object instanceof List) { 173 | List list = (List) object; 174 | CatFeature feature = (CatFeature) list.get(0); 175 | list.remove(0); 176 | 177 | Element featureDef = doc.createElement("feature"); 178 | featureDef.setAttribute("id", feature.getId()); 179 | featureDef.setAttribute("version", BundleUtils.getOSGIVersion(feature.getVersion())); 180 | for (Object catId : list) { 181 | Element category = doc.createElement("category"); 182 | category.setAttribute("name", catId.toString()); 183 | featureDef.appendChild(category); 184 | } 185 | rootElement.appendChild(featureDef); 186 | } 187 | } 188 | 189 | try { 190 | TransformerFactory transformerFactory = TransformerFactory.newInstance(); 191 | Transformer transformer; 192 | transformer = transformerFactory.newTransformer(); 193 | DOMSource source = new DOMSource(doc); 194 | StreamResult result = new StreamResult(categoryFile); 195 | transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 196 | transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); 197 | transformer.transform(source, result); 198 | } catch (TransformerConfigurationException e) { 199 | throw new TransformerConfigurationException("Unable to create feature manifest", e); 200 | } catch (TransformerException e) { 201 | throw new TransformerException("Unable to create feature manifest", e); 202 | } 203 | } 204 | 205 | /** 206 | * Returns a blank document. 207 | * 208 | * @return org.w3c.dom.Document object 209 | * @throws ParserConfigurationException throws when fail to build a new xml document 210 | */ 211 | public static Document getManifestDocument() throws ParserConfigurationException { 212 | DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); 213 | DocumentBuilder documentBuilder; 214 | documentBuilder = documentBuilderFactory.newDocumentBuilder(); 215 | return documentBuilder.newDocument(); 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/utils/P2ApplicationLaunchManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.wso2.maven.p2.utils; 18 | 19 | import org.apache.maven.plugin.MojoFailureException; 20 | import org.eclipse.sisu.equinox.launching.internal.P2ApplicationLauncher; 21 | 22 | import java.io.File; 23 | import java.io.IOException; 24 | import java.net.URL; 25 | import java.nio.file.Paths; 26 | 27 | /** 28 | * Wrapper class containing P2ApplicationLauncher which makes configuring the P2ApplicationLauncher easier. 29 | * 30 | * @since 2.0.0 31 | */ 32 | public class P2ApplicationLaunchManager { 33 | 34 | private final P2ApplicationLauncher launcher; 35 | 36 | /** 37 | * The constructor which initializes this class. This class wraps the P2ApplicationLauncher and expose a set 38 | * of simple, easy to use methods to configure the P2ApplicationLauncher. 39 | * 40 | * @param launcher P2ApplicationLauncher which will be wrapped by this wrapper class 41 | */ 42 | public P2ApplicationLaunchManager(P2ApplicationLauncher launcher) { 43 | this.launcher = launcher; 44 | } 45 | 46 | /** 47 | * Sets the working directory of P2Applilcation launcher instance. 48 | * 49 | * @param workingDir File object pointing the directory 50 | */ 51 | public void setWorkingDirectory(File workingDir) { 52 | this.launcher.setWorkingDirectory(workingDir); 53 | } 54 | 55 | /** 56 | * Sets the application name. 57 | * 58 | * @param applicationName name of the application 59 | */ 60 | public void setApplicationName(String applicationName) { 61 | this.launcher.setApplicationName(applicationName); 62 | } 63 | 64 | /** 65 | * Sets the P2ApplicationLauncher's arguments to install features. 66 | * 67 | * @param repositoryLocation a comma separated list of metadata repository(or artifact repository as in p2 both 68 | * metadata and artifacts resides in the same repo) URLs where the software to be 69 | * installed can be found. 70 | * @param installIUs a comma separated list of IUs to install. Each entry in the list is in the form 71 | * {@code [ '/' ]}. If you are looking to install a feature, the identifier 72 | * of the feature has to be suffixed with ".feature.group". 73 | * @param destination the path of a folder in which the targeted product is located. 74 | * @param profile the profile id containing the description of the targeted product. This ID is 75 | * defined by the eclipse.p2.profile property contained in the config.ini of the 76 | * targeted product. 77 | */ 78 | public void addArgumentsToInstallFeatures(String repositoryLocation, 79 | String installIUs, String destination, String profile) { 80 | 81 | launcher.addArguments( 82 | "-metadataRepository", repositoryLocation, 83 | "-artifactRepository", repositoryLocation, 84 | "-profileProperties", "org.eclipse.update.install.features=true", 85 | "-installIU", installIUs, 86 | "-bundlepool", Paths.get(destination, "lib").toString(), 87 | //to support shared installation in carbon 88 | "-shared", Paths.get(destination, "lib", "p2").toString(), 89 | //target is set to a separate directory per Profile 90 | "-destination", Paths.get(destination, profile).toString(), 91 | "-profile", profile, 92 | "-roaming"); 93 | } 94 | 95 | /** 96 | * Sets the P2ApplicationLauncher's arguments to uninstall features. 97 | * 98 | * @param uninstallIUs a comma separated list of IUs to uninstall. Each entry in the list is in the form 99 | * {@code [ '/' ]}. If you are looking to uninstall a feature, the identifier 100 | * of the feature has to be suffixed with ".feature.group". 101 | * @param destination the path of a folder in which the targeted product is located 102 | * @param profile the profile id containing the description of the targeted product 103 | */ 104 | public void addArgumentsToUnInstallFeatures(String uninstallIUs, String destination, 105 | String profile) { 106 | launcher.addArguments( 107 | "-profileProperties", "org.eclipse.update.install.features=false", 108 | // a comma separated list of IUs to uninstall. Each entry in the list is in the form 109 | // [ '/' ] 110 | "-uninstallIU", uninstallIUs, 111 | // the location of where the plug-ins and features will be stored. This value is only taken into account 112 | // when a new profile is created. For an application where all the bundles are located into the 113 | // plugins/ folder of the destination, set it to 114 | // to support shared installation in carbon 115 | "-shared", Paths.get(destination, "lib", "p2").toString(), 116 | "-destination", Paths.get(destination, profile).toString(), 117 | "-profile", profile 118 | ); 119 | } 120 | 121 | /** 122 | * Sets the P2ApplicationLauncher's arguments to generate P2 repository. For this scenario both metadata repository 123 | * and artifact repository are same. 124 | * 125 | * @param sourceDir the location of the update site 126 | * @param metadataRepoLocation the URI to the metadata repository where the installable units should be published 127 | * @param repositoryName name of the artifact repository where the artifacts should be published 128 | */ 129 | public void addRepoGenerationArguments(String sourceDir, String metadataRepoLocation, 130 | String repositoryName) { 131 | launcher.addArguments("-source", sourceDir, 132 | "-metadataRepository", metadataRepoLocation, 133 | "-metadataRepositoryName", repositoryName, 134 | "-artifactRepository", metadataRepoLocation, 135 | "-artifactRepositoryName", repositoryName, 136 | "-publishArtifacts", 137 | "-publishArtifactRepository", 138 | "-compress", 139 | "-append"); 140 | } 141 | 142 | /** 143 | * Sets the P2ApplicationLauncher's arguments and configure it to categorizing a set of Installable Units in a given 144 | * repository. 145 | * 146 | * @param metadataRepositoryLocation a comma separated list of metadata repository URLs where the software to be 147 | * installed can be found. 148 | * @param categoryDefinitionFile The category file which drives the categorization of installable units in the 149 | * repository 150 | */ 151 | public void addUpdateRepoWithCategoryArguments(String metadataRepositoryLocation, String categoryDefinitionFile) { 152 | launcher.addArguments("-metadataRepository", metadataRepositoryLocation, 153 | "-categoryDefinition", categoryDefinitionFile, 154 | "-categoryQualifier", 155 | "-compress", 156 | "-append"); 157 | 158 | } 159 | 160 | /** 161 | * Sets the P2ApplicationLauncher's arguments and configure it to publish a give product. 162 | * 163 | * @param repositoryURL the URL to the metadata repository where the product should be published 164 | * @param productConfigurationFile File object pointing the .product file 165 | * @param executable location of the equinox executable jar 166 | * @throws IOException throws when unable to get the canonical path from the product configuration file 167 | */ 168 | public void addPublishProductArguments(URL repositoryURL, File productConfigurationFile, String executable) 169 | throws IOException { 170 | launcher.addArguments( 171 | "-metadataRepository", repositoryURL.toString(), 172 | "-artifactRepository", repositoryURL.toString(), 173 | "-productFile", productConfigurationFile.getCanonicalPath(), 174 | "-executables", executable, 175 | "-publishArtifacts", 176 | "-configs", "gtk.linux.x86", 177 | "-flavor", "tooling", 178 | "-append"); 179 | 180 | } 181 | 182 | /** 183 | * Sets the P2ApplicationLauncher's arguments and configure it to generate a profile. 184 | * 185 | * @param repositoryURL the URL to the metadata repository where the product should be published 186 | * @param id product id taken from .product file 187 | * @param profile name of the new profile 188 | * @param targetPath location of the components directory of the carbon distribution 189 | */ 190 | public void addGenerateProfileArguments(URL repositoryURL, String id, String profile, URL targetPath) { 191 | launcher.addArguments( 192 | "-metadataRepository", repositoryURL.toExternalForm(), 193 | "-artifactRepository", repositoryURL.toExternalForm(), 194 | "-installIU", id, 195 | "-profileProperties", "org.eclipse.update.install.features=true", 196 | "-profile", profile, 197 | "-bundlepool", targetPath.toExternalForm() + File.separator + "lib", 198 | //to support shared installation in carbon 199 | "-shared", targetPath.toExternalForm() + File.separator + "lib" + File.separator + "p2", 200 | //target is set to a separate directory per Profile 201 | "-destination", targetPath.toExternalForm() + File.separator + profile, 202 | "-p2.os", "linux", 203 | "-p2.ws", "gtk", 204 | "-p2.arch", "x86", 205 | "-roaming" 206 | ); 207 | } 208 | 209 | /** 210 | * Generate/update the repository. 211 | * 212 | * @param forkedProcessTimeoutInSeconds int 213 | * @throws MojoFailureException throws when unable to perform the p2 activity 214 | */ 215 | public void performAction(int forkedProcessTimeoutInSeconds) throws MojoFailureException { 216 | int result = launcher.execute(forkedProcessTimeoutInSeconds); 217 | if (result != 0) { 218 | throw new MojoFailureException("P2 publisher return code was " + result); 219 | } 220 | } 221 | 222 | } 223 | -------------------------------------------------------------------------------- /carbon-feature-plugin/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | 204 | -------------------------------------------------------------------------------- /carbon-feature-plugin/src/main/java/org/wso2/maven/p2/utils/FileManagementUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.wso2.maven.p2.utils; 17 | 18 | import org.apache.maven.plugin.logging.Log; 19 | 20 | import java.io.BufferedInputStream; 21 | import java.io.BufferedOutputStream; 22 | import java.io.File; 23 | import java.io.FileInputStream; 24 | import java.io.FileOutputStream; 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | import java.io.OutputStream; 28 | import java.nio.file.Paths; 29 | import java.util.Properties; 30 | import java.util.zip.ZipEntry; 31 | import java.util.zip.ZipInputStream; 32 | import java.util.zip.ZipOutputStream; 33 | 34 | /** 35 | * Util class which handle file manipulation operations. 36 | * 37 | * @since 2.0.0 38 | */ 39 | public class FileManagementUtil { 40 | private static final int BUFFER = 2048; 41 | 42 | 43 | /** 44 | * For a given location and the profile, returns the File object represented by config.ini. 45 | * 46 | * @param destination path pointing the [carbon product]/wso2 folder 47 | * @param profile name of the profile 48 | * @return the config.ini file for the Profile 49 | */ 50 | public static File getProfileConfigIniFile(String destination, String profile) { 51 | return Paths.get(destination, profile, "configuration", "config.ini").toFile(); 52 | } 53 | 54 | /** 55 | * Updated the given config.ini file with a given key value pair. 56 | * 57 | * @param configIniFile File object representing the config.ini 58 | * @param propKey property key 59 | * @param value property value 60 | * @param log Logger to log any warnings 61 | */ 62 | public static void changeConfigIniProperty(File configIniFile, String propKey, String value, Log log) { 63 | Properties prop = new Properties(); 64 | 65 | try (InputStream inputStream = new FileInputStream(configIniFile)) { 66 | prop.load(inputStream); 67 | prop.setProperty(propKey, value); 68 | try (OutputStream outputStream = new FileOutputStream(configIniFile)) { 69 | prop.store(outputStream, null); 70 | } 71 | } catch (IOException e) { 72 | log.warn("Error occurred while updating " + configIniFile.getName(), e); 73 | } 74 | } 75 | 76 | /** 77 | * Zip a give folder to a give output zip file. 78 | * 79 | * @param srcFolder source folder 80 | * @param destZipFile path to the output zip file 81 | * @param log Logger to log any warnings 82 | */ 83 | public static void zipFolder(String srcFolder, String destZipFile, Log log) { 84 | try (FileOutputStream fileWriter = new FileOutputStream(destZipFile); 85 | ZipOutputStream zip = new ZipOutputStream(fileWriter)) { 86 | addFolderContentsToZip(srcFolder, zip, log); 87 | } catch (IOException e) { 88 | log.warn("Error occurred while archiving " + srcFolder, e); 89 | } 90 | 91 | 92 | } 93 | 94 | /** 95 | * Add a given folder/file into the given {@link ZipOutputStream}. 96 | * 97 | * @param path {@code String} Location inside the ZipOutputStream 98 | * @param srcFile {@code String} folder/file to be added into ZipOutputStream 99 | * @param zip {@link ZipOutputStream} zip output stream 100 | * @param log {@link Log} 101 | */ 102 | private static void addToZip(String path, String srcFile, ZipOutputStream zip, Log log) { 103 | File folder = new File(srcFile); 104 | if (folder.isDirectory()) { 105 | addFolderToZip(path, srcFile, zip, log); 106 | } else { 107 | // Transfer bytes from in to out 108 | byte[] buf = new byte[1024]; 109 | int len; 110 | try (FileInputStream inputStream = new FileInputStream(srcFile)) { 111 | if (path.trim().equals("")) { 112 | zip.putNextEntry(new ZipEntry(folder.getName())); 113 | } else { 114 | zip.putNextEntry(new ZipEntry(path + "/" + folder.getName())); 115 | } 116 | while ((len = inputStream.read(buf)) > 0) { 117 | zip.write(buf, 0, len); 118 | } 119 | } catch (IOException e) { 120 | log.warn("Error occurred while archiving " + srcFile, e); 121 | } 122 | } 123 | } 124 | 125 | /** 126 | * Add root level content of a folder to the given {@link ZipOutputStream}. 127 | * 128 | * @param srcFolder {@code String} location of the folder to be included into the ZipOutputStream 129 | * @param zip {@link ZipOutputStream} 130 | * @param log {@link Log} 131 | */ 132 | private static void addFolderContentsToZip(String srcFolder, ZipOutputStream zip, Log log) { 133 | File folder = new File(srcFolder); 134 | String fileList[] = folder.list(); 135 | if (fileList != null) { 136 | try { 137 | int i = 0; 138 | while (true) { 139 | if (fileList.length == i) { 140 | break; 141 | } 142 | if (new File(folder, fileList[i]).isDirectory()) { 143 | zip.putNextEntry(new ZipEntry(fileList[i] + "/")); 144 | zip.closeEntry(); 145 | } 146 | addToZip("", srcFolder + "/" + fileList[i], zip, log); 147 | i++; 148 | } 149 | } catch (IOException e) { 150 | log.warn("Error occurred while archiving " + srcFolder, e); 151 | } 152 | } 153 | } 154 | 155 | /** 156 | * Add non root level folders into a given {@link ZipOutputStream}. 157 | * @param path {@code String} 158 | * @param srcFolder {@code String} 159 | * @param zip {@link ZipOutputStream} 160 | * @param log {@link Log} 161 | */ 162 | private static void addFolderToZip(String path, String srcFolder, ZipOutputStream zip, Log log) { 163 | File folder = new File(srcFolder); 164 | String fileList[] = folder.list(); 165 | if (fileList != null) { 166 | try { 167 | int i = 0; 168 | while (true) { 169 | if (fileList.length == i) { 170 | break; 171 | } 172 | String newPath = folder.getName(); 173 | if (!path.equalsIgnoreCase("")) { 174 | newPath = path + "/" + newPath; 175 | } 176 | if (new File(folder, fileList[i]).isDirectory()) { 177 | zip.putNextEntry(new ZipEntry(newPath + "/" + fileList[i] + "/")); 178 | zip.closeEntry(); 179 | } 180 | addToZip(newPath, srcFolder + "/" + fileList[i], zip, log); 181 | i++; 182 | } 183 | } catch (IOException e) { 184 | log.warn("Error occurred while archiving " + srcFolder, e); 185 | } 186 | } 187 | } 188 | 189 | /** 190 | * Delete a given directory. 191 | * 192 | * @param dir directory to be deleted 193 | * @throws IOException throws when fail to delete a given directory 194 | */ 195 | public static void deleteDirectories(File dir) throws IOException { 196 | File[] children = dir.listFiles(); 197 | 198 | if (children != null) { 199 | for (File child : children) { 200 | if (child != null) { 201 | String[] childrenOfChild = child.list(); 202 | if (childrenOfChild != null) { 203 | if (childrenOfChild.length > 0) { 204 | deleteDirectories(child); 205 | } else { 206 | if (!child.delete()) { 207 | throw new IOException("Failed to delete " + child.getAbsolutePath()); 208 | } 209 | } 210 | } else { 211 | if (!child.delete()) { 212 | throw new IOException("Failed to delete " + child.getAbsolutePath()); 213 | } 214 | } 215 | } 216 | } 217 | if (!dir.delete()) { 218 | throw new IOException("Failed to delete " + dir.getAbsolutePath()); 219 | } 220 | } 221 | } 222 | 223 | /** 224 | * Copies all files under srcDir to dstDir. If dstDir does not exist, it will be created. 225 | * 226 | * @param srcDir source directory 227 | * @param dstDir destination directory 228 | * @throws IOException throws when fail to create the directory structure when copying files 229 | */ 230 | public static void copyDirectory(File srcDir, File dstDir) throws IOException { 231 | if (srcDir.isDirectory()) { 232 | if (!dstDir.exists()) { 233 | if (!dstDir.mkdirs()) { 234 | throw new IOException("Failed to create directory " + dstDir.getAbsolutePath()); 235 | } 236 | } 237 | 238 | String[] children = srcDir.list(); 239 | if (children != null) { 240 | for (String child : children) { 241 | copyDirectory(new File(srcDir, child), new File(dstDir, child)); 242 | } 243 | } 244 | } else { 245 | copy(srcDir, dstDir); 246 | } 247 | } 248 | 249 | /** 250 | * Copies src file to dst file. If the dst file does not exist, it is created. 251 | * 252 | * @param src source file 253 | * @param dst destination file 254 | * @throws IOException throws when fail to copy a given file 255 | */ 256 | public static void copy(File src, File dst) throws IOException { 257 | if (dst.getParentFile() != null && !dst.getParentFile().exists()) { 258 | if (!dst.getParentFile().mkdirs()) { 259 | throw new IOException("Failed to create " + dst.getAbsolutePath()); 260 | } 261 | } 262 | 263 | try (InputStream in = new FileInputStream(src); 264 | OutputStream out = new FileOutputStream(dst)) { 265 | // Transfer bytes from in to out 266 | byte[] buf = new byte[1024]; 267 | int len; 268 | while ((len = in.read(buf)) > 0) { 269 | out.write(buf, 0, len); 270 | } 271 | } 272 | } 273 | 274 | /** 275 | * Unzip a given archive to a given destination. 276 | * 277 | * @param archiveFile archive file to be unzipped 278 | * @param destination location to put the unzipped file 279 | * @throws IOException throws when fail to create the directory structure when unzipping a file. 280 | */ 281 | public static void unzip(File archiveFile, File destination) throws IOException { 282 | 283 | try (FileInputStream fis = new FileInputStream(archiveFile); 284 | ZipInputStream zis = new 285 | ZipInputStream(new BufferedInputStream(fis))) { 286 | ZipEntry entry; 287 | 288 | while ((entry = zis.getNextEntry()) != null) { 289 | int count; 290 | byte data[] = new byte[BUFFER]; 291 | File file = new File(destination, entry.getName()); 292 | if (entry.getName().endsWith("/")) { 293 | if (!file.exists() && !file.mkdirs()) { 294 | throw new IOException("Failed to create directories at " + file.getAbsolutePath()); 295 | } 296 | continue; 297 | } 298 | if (file.getParentFile() != null && !file.getParentFile().exists()) { 299 | if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) { 300 | throw new IOException("Failed to create directories at " + file.getAbsolutePath()); 301 | } 302 | } 303 | try (FileOutputStream fos = new FileOutputStream(file); 304 | BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER)) { 305 | while ((count = zis.read(data, 0, BUFFER)) != -1) { 306 | dest.write(data, 0, count); 307 | } 308 | } 309 | } 310 | } 311 | } 312 | } 313 | --------------------------------------------------------------------------------