├── .gitignore ├── .project ├── .settings ├── org.eclipse.core.resources.prefs └── org.eclipse.m2e.core.prefs ├── LICENSE ├── README.md ├── org.jboss.tools.maven.polyglot.poc.core ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ └── org.jboss.ide.eclipse.as.core.prefs ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── plugin.xml ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── jboss │ └── tools │ └── maven │ └── polyglot │ └── poc │ └── internal │ └── core │ ├── ArtifactSearcher.java │ ├── ModifiedPolyglotPomDetector.java │ ├── ModulesCollector.java │ ├── PolyglotPomChangeListener.java │ ├── PolyglotSupportActivator.java │ ├── PomTranslatorJob.java │ └── preferences │ ├── IPolyglotPreferenceConstants.java │ └── MavenPolyglotPreferenceInitializer.java ├── org.jboss.tools.maven.polyglot.poc.feature ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.m2e.core.prefs ├── build.properties ├── feature.properties ├── feature.xml ├── license.html ├── pom.xml └── sourceTemplateFeature │ └── .gitkeep ├── org.jboss.tools.maven.polyglot.poc.site ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.m2e.core.prefs ├── category.xml └── pom.xml ├── org.jboss.tools.maven.polyglot.poc.tests ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── jboss │ └── tools │ └── maven │ └── polyglot │ └── poc │ └── updater │ └── internal │ └── core │ └── ActivatorTest.java ├── org.jboss.tools.maven.polyglot.poc.ui ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ └── org.jboss.ide.eclipse.as.core.prefs ├── META-INF │ └── MANIFEST.MF ├── build.properties ├── plugin.xml ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── jboss │ └── tools │ └── maven │ └── polyglot │ └── poc │ └── internal │ └── ui │ ├── PolyglotSupportUIActivator.java │ ├── preferences │ └── MavenPolyglotPreferencePage.java │ └── translation │ ├── Language.java │ ├── PolyglotTranslaterJob.java │ ├── PolyglotTranslaterWizard.java │ ├── PolyglotTranslaterWizardPage.java │ └── TranslateToPolyglotProjectHandler.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | .DS_Store 7 | release.properties 8 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.jboss.tools.maven.polyglot.poc 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Eclipse Public License - v 1.0 2 | 3 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC 4 | LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM 5 | CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 6 | 7 | 1. DEFINITIONS 8 | 9 | "Contribution" means: 10 | 11 | a) in the case of the initial Contributor, the initial code and documentation 12 | distributed under this Agreement, and 13 | b) in the case of each subsequent Contributor: 14 | i) changes to the Program, and 15 | ii) additions to the Program; 16 | 17 | where such changes and/or additions to the Program originate from and are 18 | distributed by that particular Contributor. A Contribution 'originates' 19 | from a Contributor if it was added to the Program by such Contributor 20 | itself or anyone acting on such Contributor's behalf. Contributions do not 21 | include additions to the Program which: (i) are separate modules of 22 | software distributed in conjunction with the Program under their own 23 | license agreement, and (ii) are not derivative works of the Program. 24 | 25 | "Contributor" means any person or entity that distributes the Program. 26 | 27 | "Licensed Patents" mean patent claims licensable by a Contributor which are 28 | necessarily infringed by the use or sale of its Contribution alone or when 29 | combined with the Program. 30 | 31 | "Program" means the Contributions distributed in accordance with this 32 | Agreement. 33 | 34 | "Recipient" means anyone who receives the Program under this Agreement, 35 | including all Contributors. 36 | 37 | 2. GRANT OF RIGHTS 38 | a) Subject to the terms of this Agreement, each Contributor hereby grants 39 | Recipient a non-exclusive, worldwide, royalty-free copyright license to 40 | reproduce, prepare derivative works of, publicly display, publicly 41 | perform, distribute and sublicense the Contribution of such Contributor, 42 | if any, and such derivative works, in source code and object code form. 43 | b) Subject to the terms of this Agreement, each Contributor hereby grants 44 | Recipient a non-exclusive, worldwide, royalty-free patent license under 45 | Licensed Patents to make, use, sell, offer to sell, import and otherwise 46 | transfer the Contribution of such Contributor, if any, in source code and 47 | object code form. This patent license shall apply to the combination of 48 | the Contribution and the Program if, at the time the Contribution is 49 | added by the Contributor, such addition of the Contribution causes such 50 | combination to be covered by the Licensed Patents. The patent license 51 | shall not apply to any other combinations which include the Contribution. 52 | No hardware per se is licensed hereunder. 53 | c) Recipient understands that although each Contributor grants the licenses 54 | to its Contributions set forth herein, no assurances are provided by any 55 | Contributor that the Program does not infringe the patent or other 56 | intellectual property rights of any other entity. Each Contributor 57 | disclaims any liability to Recipient for claims brought by any other 58 | entity based on infringement of intellectual property rights or 59 | otherwise. As a condition to exercising the rights and licenses granted 60 | hereunder, each Recipient hereby assumes sole responsibility to secure 61 | any other intellectual property rights needed, if any. For example, if a 62 | third party patent license is required to allow Recipient to distribute 63 | the Program, it is Recipient's responsibility to acquire that license 64 | before distributing the Program. 65 | d) Each Contributor represents that to its knowledge it has sufficient 66 | copyright rights in its Contribution, if any, to grant the copyright 67 | license set forth in this Agreement. 68 | 69 | 3. REQUIREMENTS 70 | 71 | A Contributor may choose to distribute the Program in object code form under 72 | its own license agreement, provided that: 73 | 74 | a) it complies with the terms and conditions of this Agreement; and 75 | b) its license agreement: 76 | i) effectively disclaims on behalf of all Contributors all warranties 77 | and conditions, express and implied, including warranties or 78 | conditions of title and non-infringement, and implied warranties or 79 | conditions of merchantability and fitness for a particular purpose; 80 | ii) effectively excludes on behalf of all Contributors all liability for 81 | damages, including direct, indirect, special, incidental and 82 | consequential damages, such as lost profits; 83 | iii) states that any provisions which differ from this Agreement are 84 | offered by that Contributor alone and not by any other party; and 85 | iv) states that source code for the Program is available from such 86 | Contributor, and informs licensees how to obtain it in a reasonable 87 | manner on or through a medium customarily used for software exchange. 88 | 89 | When the Program is made available in source code form: 90 | 91 | a) it must be made available under this Agreement; and 92 | b) a copy of this Agreement must be included with each copy of the Program. 93 | Contributors may not remove or alter any copyright notices contained 94 | within the Program. 95 | 96 | Each Contributor must identify itself as the originator of its Contribution, 97 | if 98 | any, in a manner that reasonably allows subsequent Recipients to identify the 99 | originator of the Contribution. 100 | 101 | 4. COMMERCIAL DISTRIBUTION 102 | 103 | Commercial distributors of software may accept certain responsibilities with 104 | respect to end users, business partners and the like. While this license is 105 | intended to facilitate the commercial use of the Program, the Contributor who 106 | includes the Program in a commercial product offering should do so in a manner 107 | which does not create potential liability for other Contributors. Therefore, 108 | if a Contributor includes the Program in a commercial product offering, such 109 | Contributor ("Commercial Contributor") hereby agrees to defend and indemnify 110 | every other Contributor ("Indemnified Contributor") against any losses, 111 | damages and costs (collectively "Losses") arising from claims, lawsuits and 112 | other legal actions brought by a third party against the Indemnified 113 | Contributor to the extent caused by the acts or omissions of such Commercial 114 | Contributor in connection with its distribution of the Program in a commercial 115 | product offering. The obligations in this section do not apply to any claims 116 | or Losses relating to any actual or alleged intellectual property 117 | infringement. In order to qualify, an Indemnified Contributor must: 118 | a) promptly notify the Commercial Contributor in writing of such claim, and 119 | b) allow the Commercial Contributor to control, and cooperate with the 120 | Commercial Contributor in, the defense and any related settlement 121 | negotiations. The Indemnified Contributor may participate in any such claim at 122 | its own expense. 123 | 124 | For example, a Contributor might include the Program in a commercial product 125 | offering, Product X. That Contributor is then a Commercial Contributor. If 126 | that Commercial Contributor then makes performance claims, or offers 127 | warranties related to Product X, those performance claims and warranties are 128 | such Commercial Contributor's responsibility alone. Under this section, the 129 | Commercial Contributor would have to defend claims against the other 130 | Contributors related to those performance claims and warranties, and if a 131 | court requires any other Contributor to pay any damages as a result, the 132 | Commercial Contributor must pay those damages. 133 | 134 | 5. NO WARRANTY 135 | 136 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN 137 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR 138 | IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, 139 | NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each 140 | Recipient is solely responsible for determining the appropriateness of using 141 | and distributing the Program and assumes all risks associated with its 142 | exercise of rights under this Agreement , including but not limited to the 143 | risks and costs of program errors, compliance with applicable laws, damage to 144 | or loss of data, programs or equipment, and unavailability or interruption of 145 | operations. 146 | 147 | 6. DISCLAIMER OF LIABILITY 148 | 149 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY 150 | CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, 151 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION 152 | LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 153 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 154 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE 155 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY 156 | OF SUCH DAMAGES. 157 | 158 | 7. GENERAL 159 | 160 | If any provision of this Agreement is invalid or unenforceable under 161 | applicable law, it shall not affect the validity or enforceability of the 162 | remainder of the terms of this Agreement, and without further action by the 163 | parties hereto, such provision shall be reformed to the minimum extent 164 | necessary to make such provision valid and enforceable. 165 | 166 | If Recipient institutes patent litigation against any entity (including a 167 | cross-claim or counterclaim in a lawsuit) alleging that the Program itself 168 | (excluding combinations of the Program with other software or hardware) 169 | infringes such Recipient's patent(s), then such Recipient's rights granted 170 | under Section 2(b) shall terminate as of the date such litigation is filed. 171 | 172 | All Recipient's rights under this Agreement shall terminate if it fails to 173 | comply with any of the material terms or conditions of this Agreement and does 174 | not cure such failure in a reasonable period of time after becoming aware of 175 | such noncompliance. If all Recipient's rights under this Agreement terminate, 176 | Recipient agrees to cease use and distribution of the Program as soon as 177 | reasonably practicable. However, Recipient's obligations under this Agreement 178 | and any licenses granted by Recipient relating to the Program shall continue 179 | and survive. 180 | 181 | Everyone is permitted to copy and distribute copies of this Agreement, but in 182 | order to avoid inconsistency the Agreement is copyrighted and may only be 183 | modified in the following manner. The Agreement Steward reserves the right to 184 | publish new versions (including revisions) of this Agreement from time to 185 | time. No one other than the Agreement Steward has the right to modify this 186 | Agreement. The Eclipse Foundation is the initial Agreement Steward. The 187 | Eclipse Foundation may assign the responsibility to serve as the Agreement 188 | Steward to a suitable separate entity. Each new version of the Agreement will 189 | be given a distinguishing version number. The Program (including 190 | Contributions) may always be distributed subject to the version of the 191 | Agreement under which it was received. In addition, after a new version of the 192 | Agreement is published, Contributor may elect to distribute the Program 193 | (including its Contributions) under the new version. Except as expressly 194 | stated in Sections 2(a) and 2(b) above, Recipient receives no rights or 195 | licenses to the intellectual property of any Contributor under this Agreement, 196 | whether expressly, by implication, estoppel or otherwise. All rights in the 197 | Program not expressly granted under this Agreement are reserved. 198 | 199 | This Agreement is governed by the laws of the State of New York and the 200 | intellectual property laws of the United States of America. No party to this 201 | Agreement will bring a legal action under this Agreement more than one year 202 | after the cause of action arose. Each party waives its rights to a jury trial in 203 | any resulting litigation. 204 | 205 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![works badge](https://cdn.rawgit.com/nikku/works-on-my-machine/v0.2.0/badge.svg)](https://github.com/nikku/works-on-my-machine) 2 | 3 | Proof of Concept POM Polyglot support for Eclipse M2E. 4 | 5 | [Maven 3.3.1](http://takari.io/2015/03/19/polyglot-maven.html) introduced the possibility of using other formats than xml to represent the project object model (POM). 6 | 7 | In the Eclipse IDE though, M2E currently requires a pom.xml file to be able to work. 8 | 9 | This experimental plugin will allow you to edit any `pom.` and a `pom.xml` file will automatically be (re)generated (and marked as derived), allowing M2E to pick up your changes. 10 | 11 | If errors occur during the translation (due to a malformed pom for instance), the pom.xml will not be updated, so the project stays in a buildable form within Eclipse (else you'd get a blank pom.xml file). 12 | 13 | You can now convert an existing Maven project to Polyglot Maven via right-click on a project and `Configure > Convert to Maven Polyglot...` 14 | 15 | There are a few caveats though : 16 | 17 | - don't try that with the projects you care too much about, you **will** loose your original pom.xml 18 | - you can't import/start without pom.xml files first, even then you **will** loose your original pom.xml after you edit your polyglot pom 19 | - it's enabled even if no `.mvn/extensions.xml` are defined in the project ancestry, so you **will** loose your original pom.xml 20 | - M2E will most likely use a different mechanism to support polyglot Maven 21 | - did I mention you **will** loose your original pom.xml? 22 | 23 | Now projects without a polyglot pom should not be impacted. Also, you can always disable the plugin under Preferences > Maven > Polyglot Support (Experimental). 24 | 25 | Now that you've been warned, please read http://takari.io/2015/03/21/polyglot-maven.html to understand how to convert your existing pom.xml files to `pom.`. 26 | 27 | This screencast shows you how to do it from within Eclipse directly : http://screencast.com/t/ls1In7Uq (without sound) 28 | 29 | So if still want to have fun while loosing your original pom.xml files, you can install `M2E Polyglot Support Experiment` from this p2 update site : `http://dl.bintray.com/jbosstools/m2e-polyglot-poc/` 30 | 31 | This feature requires Java 1.8. If needed, you can edit your eclipse.ini (or the equivalent .ini configuration of your Eclipse based product) and add the -vm parameter, pointing at a JDK 1.8. See https://wiki.eclipse.org/Eclipse.ini#Specifying_the_JVM 32 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.jboss.tools.maven.polyglot.poc.core 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.m2e.core.maven2Nature 31 | org.eclipse.pde.PluginNature 32 | org.eclipse.jdt.core.javanature 33 | 34 | 35 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/.settings/org.jboss.ide.eclipse.as.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.jboss.ide.eclipse.as.core.singledeployable.deployableList= 3 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: M2E Polyglot Support Experiment Core Plugin 4 | Bundle-SymbolicName: org.jboss.tools.maven.polyglot.poc.core;singleton:=true 5 | Bundle-Version: 0.0.1.qualifier 6 | Bundle-Activator: org.jboss.tools.maven.polyglot.poc.internal.core.PolyglotSupportActivator 7 | Require-Bundle: org.eclipse.core.runtime, 8 | org.eclipse.core.resources, 9 | org.eclipse.m2e.core, 10 | org.slf4j.api, 11 | org.eclipse.m2e.maven.runtime 12 | Bundle-ActivationPolicy: lazy 13 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 14 | Export-Package: org.jboss.tools.maven.polyglot.poc.internal.core;x-friends:="org.jboss.tools.maven.polyglot.poc.ui", 15 | org.jboss.tools.maven.polyglot.poc.internal.core.preferences;x-friends:="org.jboss.tools.maven.polyglot.poc.ui" 16 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/main/java/ 2 | output.. = target/classes/ 3 | bin.includes = plugin.xml,\ 4 | META-INF/,\ 5 | . 6 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | org.jboss.tools.maven.polyglot.poc 5 | org.jboss.tools.maven.polyglot.poc 6 | 0.0.1-SNAPSHOT 7 | 8 | 4.0.0 9 | org.jboss.tools.maven.polyglot.poc.core 10 | eclipse-plugin 11 | ${projectName} :: core 12 | 13 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/src/main/java/org/jboss/tools/maven/polyglot/poc/internal/core/ArtifactSearcher.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.internal.core; 12 | 13 | import java.util.Collections; 14 | import java.util.List; 15 | 16 | import org.apache.maven.artifact.Artifact; 17 | import org.apache.maven.artifact.versioning.ArtifactVersion; 18 | import org.apache.maven.repository.legacy.metadata.ArtifactMetadataSource; 19 | import org.eclipse.core.runtime.CoreException; 20 | import org.eclipse.core.runtime.IProgressMonitor; 21 | import org.eclipse.core.runtime.Status; 22 | import org.eclipse.m2e.core.MavenPlugin; 23 | import org.eclipse.m2e.core.embedder.IMaven; 24 | import org.eclipse.m2e.core.internal.embedder.MavenImpl; 25 | 26 | /** 27 | * @author Fred Bricon 28 | */ 29 | @SuppressWarnings("restriction") 30 | public class ArtifactSearcher { 31 | 32 | private ArtifactSearcher() { 33 | } 34 | 35 | public static String getLatestVersion(Artifact artifact, IProgressMonitor monitor) throws CoreException { 36 | monitor.beginTask("Getting latest version for " + artifact.getGroupId() + ":" + artifact.getArtifactId(), 1); 37 | try { 38 | final IMaven maven = MavenPlugin.getMaven(); 39 | final ArtifactMetadataSource source = ((MavenImpl) maven).getPlexusContainer().lookup( 40 | ArtifactMetadataSource.class, "org.apache.maven.artifact.metadata.ArtifactMetadataSource", "maven"); //$NON-NLS-1$ $NON-NLS-2$ 41 | List versions = source.retrieveAvailableVersions(artifact, maven.getLocalRepository(), 42 | maven.getArtifactRepositories()); 43 | 44 | Collections.reverse(versions); 45 | for (ArtifactVersion artifactVersion : versions) { 46 | String version = artifactVersion.toString(); 47 | if (!version.endsWith("-SNAPSHOT")) { 48 | return version; 49 | } 50 | } 51 | } catch (Exception e) { 52 | throw new CoreException( 53 | new Status(Status.ERROR, PolyglotSupportActivator.PLUGIN_ID, "Error resolving version range", e)); //$NON-NLS-1$ 54 | } 55 | return null; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/src/main/java/org/jboss/tools/maven/polyglot/poc/internal/core/ModifiedPolyglotPomDetector.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.internal.core; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.regex.Matcher; 16 | import java.util.regex.Pattern; 17 | 18 | import org.eclipse.core.resources.IFile; 19 | import org.eclipse.core.resources.IProject; 20 | import org.eclipse.core.resources.IResource; 21 | import org.eclipse.core.resources.IResourceDelta; 22 | import org.eclipse.core.resources.IResourceDeltaVisitor; 23 | import org.eclipse.core.runtime.CoreException; 24 | 25 | /** 26 | * @author Fred Bricon 27 | */ 28 | public class ModifiedPolyglotPomDetector implements IResourceDeltaVisitor { 29 | 30 | private static final Pattern POLYGLOT_POM_PATTERN = Pattern.compile("^pom\\.(rb|groovy|yaml|scala|atom|js|kt|clj)$"); 31 | 32 | private static final String MAVEN_NATURE_ID = "org.eclipse.m2e.core.maven2Nature"; 33 | 34 | public List poms = new ArrayList<>(); 35 | 36 | @Override 37 | public boolean visit(IResourceDelta delta) throws CoreException { 38 | boolean added = false; 39 | switch (delta.getKind()) { 40 | case IResourceDelta.ADDED: 41 | added = true; 42 | case IResourceDelta.CHANGED: 43 | int flags = delta.getFlags(); 44 | if (added || (flags & IResourceDelta.CONTENT) != 0) { 45 | IResource res = delta.getResource(); 46 | if (!(res instanceof IFile) || res.isDerived()) { 47 | return true; 48 | } 49 | 50 | IFile file = (IFile) res; 51 | if (!isMavenProject(file.getProject())) { 52 | return false; 53 | } 54 | 55 | if (isAtRoot(file) && 56 | isPolyglotPom(file)) { 57 | poms.add(file); 58 | } 59 | return false; 60 | } 61 | return true; 62 | default: 63 | break; 64 | } 65 | return false; // visit the children 66 | } 67 | 68 | private boolean isAtRoot(IFile file) { 69 | return file.getProjectRelativePath().segmentCount() == 1; 70 | } 71 | 72 | protected boolean isPolyglotPom(IFile file) { 73 | Matcher m = POLYGLOT_POM_PATTERN.matcher(file.getName()); 74 | return m.matches(); 75 | } 76 | 77 | private boolean isMavenProject(IProject project) throws CoreException { 78 | return project != null && project.isAccessible() && project.hasNature(MAVEN_NATURE_ID); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/src/main/java/org/jboss/tools/maven/polyglot/poc/internal/core/ModulesCollector.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.internal.core; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Arrays; 15 | import java.util.Collections; 16 | import java.util.LinkedHashSet; 17 | import java.util.List; 18 | import java.util.Set; 19 | 20 | import org.eclipse.core.runtime.IPath; 21 | import org.eclipse.core.runtime.IProgressMonitor; 22 | import org.eclipse.m2e.core.project.IMavenProjectFacade; 23 | 24 | /** 25 | * Collects {@link IMavenProjectFacade} modules for a given {@link IMavenProjectFacade} 26 | * 27 | * @author Fred Bricon 28 | */ 29 | public class ModulesCollector { 30 | 31 | private IMavenProjectFacade parent; 32 | 33 | private LinkedHashSet modules; 34 | 35 | private List allFacades; 36 | 37 | public ModulesCollector(IMavenProjectFacade parent, IMavenProjectFacade[] allFacades) { 38 | this.parent = parent; 39 | this.allFacades = new ArrayList<>(Arrays.asList(allFacades)); 40 | this.allFacades.remove(parent); 41 | } 42 | 43 | public synchronized Set getModules(IProgressMonitor monitor) { 44 | if (modules == null) { 45 | modules = new LinkedHashSet<>(); 46 | crawlModules(parent, modules, allFacades, monitor); 47 | } 48 | return Collections.unmodifiableSet(modules); 49 | } 50 | 51 | private static void crawlModules(IMavenProjectFacade parent, LinkedHashSet modules, List allFacades, IProgressMonitor monitor) { 52 | if (!parent.getPackaging().equals("pom")) { 53 | return; 54 | } 55 | IPath path = parent.getProject().getLocation(); 56 | for (String module : parent.getMavenProjectModules()) { 57 | if (monitor.isCanceled()) { 58 | break; 59 | } 60 | IPath modulePath = path.append(module); 61 | IMavenProjectFacade moduleProject = findFacade(modulePath, allFacades); 62 | if (moduleProject != null) { 63 | modules.add(moduleProject); 64 | allFacades.remove(moduleProject); 65 | crawlModules(moduleProject, modules, allFacades, monitor); 66 | } 67 | } 68 | } 69 | 70 | private static IMavenProjectFacade findFacade(IPath modulePath, List facades) { 71 | return facades.stream() 72 | .filter(f -> modulePath.equals(f.getProject().getLocation())) 73 | .findFirst().orElse(null); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/src/main/java/org/jboss/tools/maven/polyglot/poc/internal/core/PolyglotPomChangeListener.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.internal.core; 12 | 13 | import java.util.List; 14 | 15 | import org.eclipse.core.resources.IFile; 16 | import org.eclipse.core.resources.IResourceChangeEvent; 17 | import org.eclipse.core.resources.IResourceChangeListener; 18 | import org.eclipse.core.runtime.CoreException; 19 | import org.eclipse.core.runtime.preferences.IEclipsePreferences; 20 | import org.eclipse.m2e.core.MavenPlugin; 21 | import org.eclipse.m2e.core.internal.MavenPluginActivator; 22 | import org.jboss.tools.maven.polyglot.poc.internal.core.preferences.IPolyglotPreferenceConstants; 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | 26 | /** 27 | * @author Fred Bricon 28 | */ 29 | @SuppressWarnings("restriction") 30 | public class PolyglotPomChangeListener implements IResourceChangeListener { 31 | 32 | private static Logger LOG = LoggerFactory.getLogger(PolyglotPomChangeListener.class); 33 | 34 | private IEclipsePreferences preferences; 35 | 36 | PolyglotPomChangeListener(IEclipsePreferences preferences) { 37 | this.preferences = preferences; 38 | } 39 | 40 | @Override 41 | public void resourceChanged(IResourceChangeEvent event) { 42 | if(isDisabled()) { 43 | return; 44 | } 45 | List poms = null; 46 | try { 47 | ModifiedPolyglotPomDetector visitor = new ModifiedPolyglotPomDetector(); 48 | event.getDelta().accept(visitor); 49 | poms = visitor.poms; 50 | } catch(CoreException e) { 51 | e.printStackTrace(); 52 | return; 53 | } 54 | requestPomTranslation(poms); 55 | } 56 | 57 | private boolean isDisabled() { 58 | boolean isEnabled = preferences 59 | .getBoolean(IPolyglotPreferenceConstants.ENABLE_AUTOMATIC_POM_TRANSLATION, true); 60 | return !isEnabled; 61 | } 62 | 63 | protected void requestPomTranslation(List poms) { 64 | if(poms != null && !poms.isEmpty()) { 65 | final String version = preferences.get(IPolyglotPreferenceConstants.POLYGLOT_TRANSLATION_PLUGIN_VERSION, "").trim(); 66 | LOG.debug("Automatic update of {}", poms); 67 | new PomTranslatorJob(MavenPlugin.getMavenProjectRegistry(), MavenPluginActivator.getDefault().getMavenMarkerManager(), poms, version).schedule(); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/src/main/java/org/jboss/tools/maven/polyglot/poc/internal/core/PolyglotSupportActivator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.internal.core; 12 | 13 | import org.eclipse.core.resources.IResourceChangeEvent; 14 | import org.eclipse.core.resources.IWorkspace; 15 | import org.eclipse.core.resources.ResourcesPlugin; 16 | import org.eclipse.core.runtime.Plugin; 17 | import org.eclipse.core.runtime.preferences.IEclipsePreferences; 18 | import org.eclipse.core.runtime.preferences.InstanceScope; 19 | import org.osgi.framework.BundleContext; 20 | 21 | /** 22 | * The activator class controls the plug-in life cycle 23 | */ 24 | public class PolyglotSupportActivator extends Plugin { 25 | 26 | // The plug-in ID 27 | public static final String PLUGIN_ID = "org.jboss.tools.maven.polyglot.poc.core"; 28 | 29 | // The shared instance 30 | private static PolyglotSupportActivator plugin; 31 | 32 | private PolyglotPomChangeListener polyglotPomChangeListener; 33 | 34 | /** 35 | * The constructor 36 | */ 37 | public PolyglotSupportActivator() { 38 | } 39 | 40 | public void start(BundleContext context) throws Exception { 41 | super.start(context); 42 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); 43 | polyglotPomChangeListener = new PolyglotPomChangeListener(getWorkspacePreferences()); 44 | workspace.addResourceChangeListener(polyglotPomChangeListener, IResourceChangeEvent.POST_CHANGE); 45 | plugin = this; 46 | } 47 | 48 | public void stop(BundleContext context) throws Exception { 49 | if (polyglotPomChangeListener != null) { 50 | IWorkspace workspace = ResourcesPlugin.getWorkspace(); 51 | workspace.removeResourceChangeListener(polyglotPomChangeListener); 52 | } 53 | 54 | plugin = null; 55 | super.stop(context); 56 | } 57 | 58 | /** 59 | * @return the shared instance 60 | */ 61 | public static PolyglotSupportActivator getDefault() { 62 | return plugin; 63 | } 64 | 65 | public IEclipsePreferences getWorkspacePreferences() { 66 | return InstanceScope.INSTANCE.getNode(PLUGIN_ID); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/src/main/java/org/jboss/tools/maven/polyglot/poc/internal/core/PomTranslatorJob.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.internal.core; 12 | 13 | import java.io.File; 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.Collection; 19 | import java.util.List; 20 | import java.util.Properties; 21 | import java.util.regex.Matcher; 22 | import java.util.regex.Pattern; 23 | 24 | import org.apache.maven.Maven; 25 | import org.apache.maven.execution.MavenExecutionRequest; 26 | import org.apache.maven.execution.MavenExecutionResult; 27 | import org.apache.maven.project.MavenProject; 28 | import org.eclipse.core.resources.IFile; 29 | import org.eclipse.core.resources.IFolder; 30 | import org.eclipse.core.resources.IMarker; 31 | import org.eclipse.core.resources.IProject; 32 | import org.eclipse.core.resources.IResource; 33 | import org.eclipse.core.runtime.Assert; 34 | import org.eclipse.core.runtime.CoreException; 35 | import org.eclipse.core.runtime.IPath; 36 | import org.eclipse.core.runtime.IProgressMonitor; 37 | import org.eclipse.core.runtime.IStatus; 38 | import org.eclipse.core.runtime.Status; 39 | import org.eclipse.core.runtime.jobs.Job; 40 | import org.eclipse.m2e.core.MavenPlugin; 41 | import org.eclipse.m2e.core.embedder.ICallable; 42 | import org.eclipse.m2e.core.embedder.IMaven; 43 | import org.eclipse.m2e.core.embedder.IMavenExecutionContext; 44 | import org.eclipse.m2e.core.internal.IMavenConstants; 45 | import org.eclipse.m2e.core.internal.MavenPluginActivator; 46 | import org.eclipse.m2e.core.internal.embedder.MavenImpl; 47 | import org.eclipse.m2e.core.internal.markers.IMavenMarkerManager; 48 | import org.eclipse.m2e.core.project.IMavenProjectFacade; 49 | import org.eclipse.m2e.core.project.IMavenProjectRegistry; 50 | import org.slf4j.Logger; 51 | import org.slf4j.LoggerFactory; 52 | 53 | /** 54 | * @author Fred Bricon 55 | */ 56 | @SuppressWarnings("restriction") 57 | public class PomTranslatorJob extends Job { 58 | 59 | private static final Logger LOG = LoggerFactory.getLogger(PomTranslatorJob.class); 60 | 61 | private static final String TRANSLATION_PROBLEM_TYPE = "mavenPolyglotProblem.translationError"; 62 | 63 | private static final Pattern LINE_COL_INFO_PATTERN = Pattern.compile("line (\\d+), column"); 64 | 65 | private List poms; 66 | 67 | private IMavenProjectRegistry projectManager; 68 | 69 | private IMavenMarkerManager markerManager; 70 | 71 | final private String translatePluginVersion; 72 | 73 | 74 | public PomTranslatorJob(List poms, String translatePluginVersion) { 75 | this(MavenPlugin.getMavenProjectRegistry(), MavenPluginActivator.getDefault().getMavenMarkerManager(), poms, translatePluginVersion); 76 | } 77 | 78 | public PomTranslatorJob(IMavenProjectRegistry projectManager, IMavenMarkerManager markerManager, List poms, String translatePluginVersion) { 79 | super("Pom translator"); 80 | Assert.isNotNull(poms); 81 | this.projectManager = projectManager; 82 | this.markerManager = markerManager; 83 | this.poms = new ArrayList<>(poms); 84 | this.translatePluginVersion = translatePluginVersion; 85 | } 86 | 87 | @Override 88 | protected IStatus run(IProgressMonitor monitor) { 89 | LOG.debug("Translating "+poms); 90 | for (IFile input : poms) { 91 | if (monitor.isCanceled()) { 92 | break; 93 | } 94 | try { 95 | translatePom(input, monitor); 96 | } catch (CoreException O_o) { 97 | IStatus error = new Status(IStatus.ERROR, PolyglotSupportActivator.PLUGIN_ID, "Unable to translate "+input + " to pom.xml", O_o); 98 | return error; 99 | } 100 | } 101 | return Status.OK_STATUS; 102 | } 103 | 104 | private void translatePom(IFile input, IProgressMonitor monitor) throws CoreException { 105 | markerManager.deleteMarkers(input, TRANSLATION_PROBLEM_TYPE); 106 | 107 | IProject project = input.getProject(); 108 | IFile pomXml = project.getFile(IMavenConstants.POM_FILE_NAME); 109 | IPath buildFolder; 110 | if (pomXml.exists()) { 111 | IMavenProjectFacade facade = projectManager.create(pomXml, true, monitor); 112 | MavenProject mavenProject = facade.getMavenProject(monitor); 113 | buildFolder = facade.getProjectRelativePath(mavenProject.getBuild().getDirectory()); 114 | } else { 115 | //In case where pom.xml doesn't exist, fall back to default target folder 116 | buildFolder = project.getFolder("target").getProjectRelativePath(); 117 | } 118 | 119 | IPath polyglotFolder = buildFolder.append("polyglot"); 120 | IFile output = project.getFolder(polyglotFolder).getFile(IMavenConstants.POM_FILE_NAME); 121 | MavenExecutionResult result = translate(pomXml, input, output, monitor); 122 | if (result.hasExceptions()) { 123 | addErrorMarkers(input, result.getExceptions()); 124 | return; 125 | } 126 | 127 | if (output.exists()) { 128 | try (InputStream content = output.getContents()) { 129 | if (pomXml.exists()) { 130 | pomXml.setContents(content, true, true, monitor); 131 | } else { 132 | pomXml.create(content, true, monitor); 133 | } 134 | if (!pomXml.isDerived()) { 135 | pomXml.setDerived(true, monitor); 136 | } 137 | } catch (IOException e) { 138 | throw new CoreException(new Status(IStatus.ERROR, PolyglotSupportActivator.PLUGIN_ID, "Unable to write to pom.xml", e)); 139 | } 140 | } 141 | } 142 | 143 | private void addErrorMarkers(IFile input, Collection errors) { 144 | for (Throwable O_o : errors) { 145 | String msg = ""+O_o.getMessage(); 146 | Matcher m = LINE_COL_INFO_PATTERN.matcher(msg); 147 | if (m.find()) { 148 | int line = Integer.parseInt(m.group(1)); 149 | markerManager.addMarker(input, TRANSLATION_PROBLEM_TYPE, msg, line, IMarker.SEVERITY_ERROR); 150 | } else { 151 | markerManager.addErrorMarkers(input, TRANSLATION_PROBLEM_TYPE, O_o); 152 | } 153 | 154 | } 155 | } 156 | 157 | protected MavenExecutionResult translate(IFile pom, IFile input, IFile output, IProgressMonitor monitor) throws CoreException { 158 | final IMaven maven = MavenPlugin.getMaven(); 159 | IMavenExecutionContext context = maven.createExecutionContext(); 160 | final MavenExecutionRequest request = context.getExecutionRequest(); 161 | File pomFile = pom.getRawLocation().toFile(); 162 | request.setBaseDirectory(pomFile.getParentFile()); 163 | final String pluginTargetLine = "io.takari.polyglot:polyglot-translate-plugin" + 164 | (translatePluginVersion.isEmpty() ? "" : ":" + translatePluginVersion) + 165 | ":translate"; 166 | request.setGoals(Arrays.asList(pluginTargetLine)); 167 | request.setUpdateSnapshots(false); 168 | Properties props = new Properties(); 169 | props.put("input", input.getRawLocation().toOSString()); 170 | String rawDestination = output.getRawLocation().toOSString(); 171 | props.put("output", rawDestination); 172 | request.setUserProperties(props); 173 | 174 | new File(rawDestination).getParentFile().mkdirs(); 175 | 176 | MavenExecutionResult result = context.execute(new ICallable() { 177 | public MavenExecutionResult call(IMavenExecutionContext context, IProgressMonitor innerMonitor) throws CoreException { 178 | return ((MavenImpl)maven).lookupComponent(Maven.class) 179 | .execute(request); 180 | } 181 | }, monitor); 182 | 183 | output.refreshLocal(IResource.DEPTH_ZERO, monitor); 184 | return result; 185 | } 186 | 187 | } 188 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/src/main/java/org/jboss/tools/maven/polyglot/poc/internal/core/preferences/IPolyglotPreferenceConstants.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.internal.core.preferences; 12 | 13 | /** 14 | * m2e-polyglot preference constants 15 | * 16 | * @author Fred Bricon 17 | */ 18 | public interface IPolyglotPreferenceConstants { 19 | 20 | String ENABLE_AUTOMATIC_POM_TRANSLATION = "polyglot.maven.autoPomTranslation"; 21 | 22 | String POLYGLOT_TRANSLATION_PLUGIN_VERSION = "polyglot.maven.translationPluginVersion"; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.core/src/main/java/org/jboss/tools/maven/polyglot/poc/internal/core/preferences/MavenPolyglotPreferenceInitializer.java: -------------------------------------------------------------------------------- 1 | /************************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * JBoss by Red Hat - Initial implementation. 10 | ************************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.internal.core.preferences; 12 | 13 | import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; 14 | import org.eclipse.core.runtime.preferences.DefaultScope; 15 | import org.eclipse.core.runtime.preferences.IEclipsePreferences; 16 | import org.jboss.tools.maven.polyglot.poc.internal.core.PolyglotSupportActivator; 17 | 18 | /** 19 | * Preferences initializer. 20 | * 21 | * @author Fred Bricon 22 | */ 23 | public class MavenPolyglotPreferenceInitializer extends AbstractPreferenceInitializer { 24 | 25 | /** 26 | * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() 27 | */ 28 | @Override 29 | public void initializeDefaultPreferences() { 30 | final IEclipsePreferences store = DefaultScope.INSTANCE.getNode(PolyglotSupportActivator.PLUGIN_ID); 31 | store.putBoolean(IPolyglotPreferenceConstants.ENABLE_AUTOMATIC_POM_TRANSLATION, true); 32 | store.put(IPolyglotPreferenceConstants.POLYGLOT_TRANSLATION_PLUGIN_VERSION, ""); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.feature/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.jboss.tools.maven.polyglot.poc.feature 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.pde.FeatureBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.m2e.core.maven2Nature 21 | org.eclipse.pde.FeatureNature 22 | 23 | 24 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.feature/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.feature/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.feature/build.properties: -------------------------------------------------------------------------------- 1 | bin.includes = feature.xml,\ 2 | feature.properties,\ 3 | license.html 4 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.feature/feature.properties: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (c) 2015 Red Hat, Inc. and others. 3 | # All rights reserved. This program and the accompanying materials 4 | # are made available under the terms of the Eclipse Public License v1.0 5 | # which accompanies this distribution, and is available at 6 | # http://www.eclipse.org/legal/epl-v10.html 7 | # 8 | # Contributors: 9 | # JBoss by Red Hat - Initial implementation. 10 | ############################################################################## 11 | # feature.properties 12 | # contains externalized strings for feature.xml 13 | # "%foo" in feature.xml corresponds to the key "foo" in this file 14 | # java.io.Properties file (ISO 8859-1 with "\" escapes) 15 | # This file should be translated. 16 | 17 | # "featureName" property - name of the feature 18 | featureName=M2E Polyglot Support Experiment 19 | 20 | # "providerName" property - name of the company that provides the feature 21 | providerName=JBoss by Red Hat 22 | 23 | # "updateSiteName" property - label for the update site 24 | updateSiteName=JBossTools Update Site 25 | 26 | # "description" property - description of the feature 27 | description=This feature provides *higly experimental* support for Maven Polyglot within Eclipse. 28 | 29 | # "copyright" property - text of the "Feature Update Copyright" 30 | copyright=Copyright (c) 2015 Red Hat, Inc. and others.\n\ 31 | All rights reserved. This program and the accompanying materials\n\ 32 | are made available under the terms of the Eclipse Public License v1.0\n\ 33 | which accompanies this distribution, and is available at\n\ 34 | http\://www.eclipse.org/legal/epl-v10.html\n\nContributors\:\n\ 35 | JBoss by Red Hat - Initial implementation. 36 | ############### end of copyright property #################################### 37 | 38 | # "licenseURL" property - URL of the "Feature License" 39 | # do not translate value - just change to point to a locale-specific HTML page 40 | licenseURL=license.html 41 | 42 | # START NON-TRANSLATABLE 43 | # "license" property - text of the "Feature Update License" 44 | # should be plain text version of license agreement pointed to be "licenseURL" 45 | license=Red Hat, Inc. licenses these features and plugins to you under \ 46 | certain open source licenses (or aggregations of such licenses), which \ 47 | in a particular case may include the Eclipse Public License, the GNU \ 48 | Lesser General Public License, and/or certain other open source \ 49 | licenses. For precise licensing details, consult the corresponding \ 50 | source code, or contact Red Hat Legal Affairs, 1801 Varsity Drive, \ 51 | Raleigh NC 27606 USA. 52 | # END NON-TRANSLATABLE 53 | ########### end of license property ########################################## 54 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.feature/feature.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %description 6 | 7 | 8 | 9 | %copyright 10 | 11 | 12 | 13 | %license 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.feature/license.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

Red Hat, Inc. licenses these features and plugins to you under 6 | certain open source licenses (or aggregations of such licenses), which 7 | in a particular case may include the Eclipse Public License, the GNU 8 | Lesser General Public License, and/or certain other open source 9 | licenses. For precise licensing details, consult the corresponding 10 | source code, or contact Red Hat Legal Affairs, 1801 Varsity Drive, 11 | Raleigh NC 27606 USA. 12 |

13 | 14 | 15 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.feature/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | org.jboss.tools.maven.polyglot.poc 6 | org.jboss.tools.maven.polyglot.poc 7 | 0.0.1-SNAPSHOT 8 | 9 | org.jboss.tools.maven.polyglot.poc.feature 10 | eclipse-feature 11 | ${projectName} :: feature 12 | 13 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.feature/sourceTemplateFeature/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbosstools/m2e-polyglot-poc/0fbc97aa8eb2a94362248f6ad1f9a1d1d21824db/org.jboss.tools.maven.polyglot.poc.feature/sourceTemplateFeature/.gitkeep -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.site/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.jboss.tools.maven.polyglot.poc.site 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.site/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.site/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.site/category.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.site/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | org.jboss.tools.maven.polyglot.poc 6 | org.jboss.tools.maven.polyglot.poc 7 | 0.0.1-SNAPSHOT 8 | 9 | org.jboss.tools.maven.polyglot.poc.site 10 | eclipse-repository 11 | ${projectName} :: update site 12 | 13 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.tests/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.tests/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.jboss.tools.maven.polyglot.poc.tests 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.ManifestBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.pde.SchemaBuilder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.m2e.core.maven2Nature 31 | org.eclipse.pde.PluginNature 32 | org.eclipse.jdt.core.javanature 33 | 34 | 35 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.tests/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.tests/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.compliance=1.7 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.7 8 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.tests/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.tests/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: M2E Polyglot Support Experiment UI Plugin Test Fragment 4 | Bundle-SymbolicName: org.jboss.tools.maven.polyglot.poc.tests 5 | Bundle-Version: 0.0.1.qualifier 6 | Fragment-Host: org.jboss.tools.maven.polyglot.poc.core;bundle-version="0.0.1" 7 | Bundle-RequiredExecutionEnvironment: JavaSE-1.7 8 | Require-Bundle: org.eclipse.jdt.junit4.runtime;bundle-version="1.1.0", 9 | org.junit;bundle-version="4.11" 10 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.tests/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/main/java/ 2 | output.. = target/classes/ 3 | bin.includes = META-INF/,\ 4 | . 5 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.tests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | org.jboss.tools.maven.polyglot.poc 5 | org.jboss.tools.maven.polyglot.poc 6 | 0.0.1-SNAPSHOT 7 | 8 | 4.0.0 9 | org.jboss.tools.maven.polyglot.poc.tests 10 | eclipse-test-plugin 11 | ${projectName} :: tests 12 | 13 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.tests/src/main/java/org/jboss/tools/maven/polyglot/poc/updater/internal/core/ActivatorTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.updater.internal.core; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | 15 | import org.jboss.tools.maven.polyglot.poc.translator.internal.core.PolyglotSupportActivator; 16 | import org.junit.Test; 17 | 18 | /** 19 | * Sample integration test. In Eclipse, right-click > Run As > JUnit-Plugin.
20 | * In Maven CLI, run "mvn integration-test". 21 | */ 22 | public class ActivatorTest { 23 | 24 | @Test 25 | public void veryStupidTest() { 26 | assertEquals("org.jboss.tools.maven.polyglot.poc.core",PolyglotSupportActivator.PLUGIN_ID); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.jboss.tools.maven.polyglot.poc.core 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.m2e.core.maven2Nature 31 | org.eclipse.pde.PluginNature 32 | org.eclipse.jdt.core.javanature 33 | 34 | 35 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/.settings/org.jboss.ide.eclipse.as.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.jboss.ide.eclipse.as.core.singledeployable.deployableList= 3 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: M2E Polyglot Support Experiment UI Plugin 4 | Bundle-SymbolicName: org.jboss.tools.maven.polyglot.poc.ui;singleton:=true 5 | Bundle-Version: 0.0.1.qualifier 6 | Bundle-Activator: org.jboss.tools.maven.polyglot.poc.internal.ui.PolyglotSupportUIActivator 7 | Require-Bundle: org.eclipse.ui, 8 | org.eclipse.core.runtime, 9 | org.eclipse.core.resources, 10 | org.eclipse.m2e.core, 11 | org.slf4j.api, 12 | org.eclipse.m2e.maven.runtime, 13 | org.jboss.tools.maven.polyglot.poc.core 14 | Bundle-ActivationPolicy: lazy 15 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 16 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/main/java/ 2 | output.. = target/classes/ 3 | bin.includes = plugin.xml,\ 4 | META-INF/,\ 5 | . 6 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | 10 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | 23 | 25 | 28 | 31 | 33 | 44 | 45 | 46 | 47 | 48 | 50 | 53 | 54 | 55 | 57 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | org.jboss.tools.maven.polyglot.poc 5 | org.jboss.tools.maven.polyglot.poc 6 | 0.0.1-SNAPSHOT 7 | 8 | 4.0.0 9 | org.jboss.tools.maven.polyglot.poc.ui 10 | eclipse-plugin 11 | ${projectName} :: ui 12 | 13 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/src/main/java/org/jboss/tools/maven/polyglot/poc/internal/ui/PolyglotSupportUIActivator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.internal.ui; 12 | 13 | import org.eclipse.core.runtime.Plugin; 14 | import org.eclipse.core.runtime.preferences.InstanceScope; 15 | import org.eclipse.jface.preference.IPreferenceStore; 16 | import org.eclipse.ui.IStartup; 17 | import org.eclipse.ui.preferences.ScopedPreferenceStore; 18 | import org.jboss.tools.maven.polyglot.poc.internal.core.PolyglotSupportActivator; 19 | import org.jboss.tools.maven.polyglot.poc.internal.core.preferences.IPolyglotPreferenceConstants; 20 | import org.osgi.framework.BundleContext; 21 | 22 | /** 23 | * The activator class controls the plug-in life cycle 24 | */ 25 | public class PolyglotSupportUIActivator extends Plugin implements IStartup { 26 | 27 | // The plug-in ID 28 | public static final String PLUGIN_ID = "org.jboss.tools.maven.polyglot.poc.ui"; 29 | 30 | // The shared instance 31 | private static PolyglotSupportUIActivator plugin; 32 | 33 | private IPreferenceStore preferenceStore; 34 | 35 | public void start(BundleContext context) throws Exception { 36 | super.start(context); 37 | //forces activation of core plugin 38 | getPreferenceStore().getBoolean(IPolyglotPreferenceConstants.ENABLE_AUTOMATIC_POM_TRANSLATION); 39 | getPreferenceStore().getString(IPolyglotPreferenceConstants.POLYGLOT_TRANSLATION_PLUGIN_VERSION); 40 | plugin = this; 41 | } 42 | 43 | public void stop(BundleContext context) throws Exception { 44 | plugin = null; 45 | preferenceStore = null; 46 | super.stop(context); 47 | } 48 | 49 | /** 50 | * @return the shared instance 51 | */ 52 | public static PolyglotSupportUIActivator getDefault() { 53 | return plugin; 54 | } 55 | 56 | @Override 57 | public void earlyStartup() { 58 | } 59 | 60 | public IPreferenceStore getPreferenceStore() { 61 | if (preferenceStore == null) { 62 | preferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE,PolyglotSupportActivator.PLUGIN_ID); 63 | } 64 | return preferenceStore; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/src/main/java/org/jboss/tools/maven/polyglot/poc/internal/ui/preferences/MavenPolyglotPreferencePage.java: -------------------------------------------------------------------------------- 1 | /************************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. and others. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * JBoss by Red Hat - Initial implementation. 10 | ************************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.internal.ui.preferences; 12 | 13 | import org.eclipse.jface.preference.BooleanFieldEditor; 14 | import org.eclipse.jface.preference.FieldEditorPreferencePage; 15 | import org.eclipse.jface.preference.StringFieldEditor; 16 | import org.eclipse.ui.IWorkbench; 17 | import org.eclipse.ui.IWorkbenchPreferencePage; 18 | import org.jboss.tools.maven.polyglot.poc.internal.core.preferences.IPolyglotPreferenceConstants; 19 | import org.jboss.tools.maven.polyglot.poc.internal.ui.PolyglotSupportUIActivator; 20 | 21 | /** 22 | * @author Fred Bricon 23 | */ 24 | public class MavenPolyglotPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { 25 | 26 | public MavenPolyglotPreferencePage() { 27 | super(GRID); 28 | setPreferenceStore(PolyglotSupportUIActivator.getDefault().getPreferenceStore()); 29 | } 30 | 31 | public void init(IWorkbench workbench) { 32 | } 33 | 34 | public void createFieldEditors() { 35 | addField(new BooleanFieldEditor(IPolyglotPreferenceConstants.ENABLE_AUTOMATIC_POM_TRANSLATION, 36 | "Enable automatic polyglot pom translation. pom.xml will be overwritten!", 37 | getFieldEditorParent())); 38 | addField(new StringFieldEditor(IPolyglotPreferenceConstants.POLYGLOT_TRANSLATION_PLUGIN_VERSION, 39 | "Optional version of the polyglot-translate-plugin", 40 | getFieldEditorParent())); 41 | } 42 | 43 | @Override 44 | public boolean performOk() { 45 | if (super.performOk()) { 46 | } 47 | System.err.println(getPreferenceStore().needsSaving()); 48 | return true; 49 | } 50 | } -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/src/main/java/org/jboss/tools/maven/polyglot/poc/internal/ui/translation/Language.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.internal.ui.translation; 12 | 13 | /** 14 | * @author Fred Bricon 15 | */ 16 | public enum Language { 17 | 18 | atom, 19 | //clojure("clj"), clojure seems broken 20 | groovy, 21 | ruby("rb"), 22 | scala, 23 | yaml; 24 | 25 | private String fileExtension; 26 | private String mavenPluginId; 27 | 28 | Language() { 29 | this.fileExtension = name(); 30 | this.mavenPluginId = "polyglot-"+name(); 31 | } 32 | 33 | Language(String extension) { 34 | this(); 35 | this.fileExtension = extension; 36 | } 37 | 38 | public String getFileExtension() { 39 | return fileExtension; 40 | } 41 | 42 | public String getMavenPluginId() { 43 | return mavenPluginId; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/src/main/java/org/jboss/tools/maven/polyglot/poc/internal/ui/translation/PolyglotTranslaterJob.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.internal.ui.translation; 12 | 13 | import java.io.BufferedWriter; 14 | import java.io.File; 15 | import java.io.FileInputStream; 16 | import java.io.FileOutputStream; 17 | import java.io.OutputStreamWriter; 18 | import java.io.PrintWriter; 19 | import java.io.StringReader; 20 | import java.io.Writer; 21 | import java.util.ArrayList; 22 | import java.util.Collections; 23 | import java.util.List; 24 | import java.util.Set; 25 | 26 | import org.apache.maven.artifact.Artifact; 27 | import org.apache.maven.artifact.DefaultArtifact; 28 | import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; 29 | import org.codehaus.plexus.util.xml.Xpp3Dom; 30 | import org.codehaus.plexus.util.xml.Xpp3DomBuilder; 31 | import org.codehaus.plexus.util.xml.Xpp3DomWriter; 32 | import org.eclipse.core.resources.IFile; 33 | import org.eclipse.core.resources.IResource; 34 | import org.eclipse.core.runtime.CoreException; 35 | import org.eclipse.core.runtime.IProgressMonitor; 36 | import org.eclipse.core.runtime.IStatus; 37 | import org.eclipse.core.runtime.Path; 38 | import org.eclipse.core.runtime.Status; 39 | import org.eclipse.m2e.core.MavenPlugin; 40 | import org.eclipse.m2e.core.project.IMavenProjectFacade; 41 | import org.jboss.tools.maven.polyglot.poc.internal.core.ArtifactSearcher; 42 | import org.jboss.tools.maven.polyglot.poc.internal.core.ModulesCollector; 43 | import org.jboss.tools.maven.polyglot.poc.internal.core.PomTranslatorJob; 44 | import org.jboss.tools.maven.polyglot.poc.internal.ui.PolyglotSupportUIActivator; 45 | 46 | /** 47 | * @author Fred Bricon 48 | */ 49 | public class PolyglotTranslaterJob extends PomTranslatorJob { 50 | 51 | private IMavenProjectFacade facade; 52 | private Language language; 53 | private boolean addExtension; 54 | private File mvnExtensionsDir; 55 | 56 | public PolyglotTranslaterJob(IMavenProjectFacade facade, Language language, boolean addExtension, File mvnExtensionsDir, String translatePluginVersion) { 57 | super(Collections.singletonList(facade.getPom()), translatePluginVersion); 58 | this.facade = facade; 59 | this.language = language; 60 | this.addExtension = addExtension; 61 | this.mvnExtensionsDir = mvnExtensionsDir; 62 | } 63 | 64 | @Override 65 | protected IStatus run(IProgressMonitor monitor) { 66 | try { 67 | if (addExtension) { 68 | Artifact extension = findLatestExtensionFor(language.getMavenPluginId(), monitor); 69 | monitor.worked(1); 70 | addExtension(mvnExtensionsDir, extension); 71 | monitor.worked(1); 72 | } 73 | 74 | IMavenProjectFacade[] allFacades = MavenPlugin.getMavenProjectRegistry().getProjects(); 75 | Set modules = new ModulesCollector(facade, allFacades).getModules(monitor); 76 | List facades = new ArrayList<>(modules.size()+1); 77 | facades.add(facade); 78 | facades.addAll(modules); 79 | for (IMavenProjectFacade f : facades) { 80 | IFile output = f.getPom().getParent().getFile(new Path("pom."+language.getFileExtension())); 81 | translate(f.getPom(), f.getPom(), output, monitor); 82 | facade.getProject().refreshLocal(IResource.DEPTH_ZERO, monitor); 83 | monitor.worked(1); 84 | } 85 | } catch (Exception e) { 86 | e.printStackTrace(); 87 | if (e instanceof CoreException) { 88 | return ((CoreException)e).getStatus(); 89 | } 90 | return new Status(IStatus.ERROR, PolyglotSupportUIActivator.PLUGIN_ID, e.getMessage()); 91 | } 92 | return Status.OK_STATUS; 93 | } 94 | 95 | private void addExtension(File mvnExtensionsDir, Artifact extension) throws Exception { 96 | mvnExtensionsDir.mkdirs(); 97 | File mvnExtension = new File(mvnExtensionsDir, "extensions.xml"); 98 | Xpp3Dom dom = null; 99 | if (mvnExtension.exists()) {//TODO could make check more robust 100 | try (FileInputStream fis = new FileInputStream(mvnExtension)) { 101 | dom = Xpp3DomBuilder.build(fis, "UTF-8"); 102 | } 103 | } else { 104 | dom = Xpp3DomBuilder.build(new StringReader("\n")); 105 | } 106 | Xpp3Dom[] extensions = dom.getChildren("extension"); 107 | if (extensions != null && extensions.length > 0) { 108 | for (Xpp3Dom ex : extensions) { 109 | String groupId = ex.getChild("groupId").getValue(); 110 | String artifactId = ex.getChild("artifactId").getValue(); 111 | if (extension.getArtifactId().equals(artifactId) && extension.getGroupId().equals(groupId)) { 112 | //nothing to do 113 | return; 114 | } 115 | } 116 | } 117 | Xpp3Dom newExtension = new Xpp3Dom("extension"); 118 | addNode(newExtension, "groupId", extension.getGroupId()); 119 | addNode(newExtension, "artifactId", extension.getArtifactId()); 120 | addNode(newExtension, "version", extension.getVersion()); 121 | dom.addChild(newExtension); 122 | 123 | try (Writer writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(mvnExtension),"UTF-8")))) { 124 | Xpp3DomWriter.write(new PrettyPrintXMLWriter(writer), dom); 125 | } 126 | } 127 | 128 | private Artifact findLatestExtensionFor(String pluginId, IProgressMonitor monitor) { 129 | final Artifact extension = new DefaultArtifact("io.takari.polyglot", pluginId, "0.3.0", null, "jar", "", null); 130 | try { 131 | String latestVersion = ArtifactSearcher.getLatestVersion(extension, monitor); 132 | if (latestVersion != null) { 133 | extension.setVersion(latestVersion); 134 | } 135 | } catch (CoreException e) { 136 | e.printStackTrace(); 137 | } 138 | return extension; 139 | } 140 | 141 | private static void addNode(Xpp3Dom parent, String key, String value) { 142 | Xpp3Dom node = new Xpp3Dom(key); 143 | node.setValue(value); 144 | parent.addChild(node); 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/src/main/java/org/jboss/tools/maven/polyglot/poc/internal/ui/translation/PolyglotTranslaterWizard.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.internal.ui.translation; 12 | 13 | import java.io.File; 14 | import java.lang.reflect.InvocationTargetException; 15 | 16 | import org.eclipse.core.runtime.IProgressMonitor; 17 | import org.eclipse.core.runtime.IStatus; 18 | import org.eclipse.jface.dialogs.MessageDialog; 19 | import org.eclipse.jface.operation.IRunnableWithProgress; 20 | import org.eclipse.jface.wizard.Wizard; 21 | import org.eclipse.m2e.core.project.IMavenProjectFacade; 22 | import org.jboss.tools.maven.polyglot.poc.internal.core.preferences.IPolyglotPreferenceConstants; 23 | import org.jboss.tools.maven.polyglot.poc.internal.ui.PolyglotSupportUIActivator; 24 | 25 | /** 26 | * @author Fred Bricon 27 | */ 28 | public class PolyglotTranslaterWizard extends Wizard { 29 | 30 | private PolyglotTranslaterWizardPage translaterPage; 31 | private IMavenProjectFacade facade; 32 | 33 | public PolyglotTranslaterWizard(IMavenProjectFacade facade) { 34 | this.facade = facade; 35 | setNeedsProgressMonitor(true); 36 | } 37 | 38 | @Override 39 | public void addPages() { 40 | translaterPage = new PolyglotTranslaterWizardPage(facade); 41 | addPage(translaterPage); 42 | } 43 | 44 | @Override 45 | public boolean performFinish() { 46 | final String versionOrNull = PolyglotSupportUIActivator.getDefault().getPreferenceStore().getString(IPolyglotPreferenceConstants.POLYGLOT_TRANSLATION_PLUGIN_VERSION); 47 | final String version = versionOrNull == null ? "" : versionOrNull.trim(); 48 | 49 | final Language language = translaterPage.getLanguage(); 50 | final boolean isAddExtension = translaterPage.isAddExtension(); 51 | final File mvnExtensionsDir = translaterPage.getMvnExtensionsDir(); 52 | IRunnableWithProgress op = new IRunnableWithProgress() { 53 | public void run(IProgressMonitor monitor) throws InvocationTargetException { 54 | monitor.beginTask("Project Translation", 3); 55 | try { 56 | // No, this is not how Jobs are supposed to be used 57 | final IStatus result = new PolyglotTranslaterJob(facade, language, isAddExtension, mvnExtensionsDir, version) 58 | .run(monitor); 59 | if (!result.isOK()) { 60 | throw new InvocationTargetException(result.getException()); 61 | } 62 | } catch (Exception e) { 63 | e.printStackTrace(); 64 | throw new InvocationTargetException(e); 65 | } finally { 66 | monitor.done(); 67 | } 68 | } 69 | }; 70 | 71 | try { 72 | getContainer().run(true, true, op); 73 | } catch (InterruptedException e) { 74 | return false; 75 | } catch (InvocationTargetException e) { 76 | Throwable realException = e.getTargetException(); 77 | MessageDialog.openError(getShell(), "Translation failed", realException.getMessage()); 78 | return false; 79 | } 80 | return true; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/src/main/java/org/jboss/tools/maven/polyglot/poc/internal/ui/translation/PolyglotTranslaterWizardPage.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.internal.ui.translation; 12 | 13 | import java.io.File; 14 | import java.util.Arrays; 15 | import java.util.stream.Collectors; 16 | 17 | import org.eclipse.jface.wizard.WizardPage; 18 | import org.eclipse.m2e.core.project.IMavenProjectFacade; 19 | import org.eclipse.swt.SWT; 20 | import org.eclipse.swt.layout.GridData; 21 | import org.eclipse.swt.layout.GridLayout; 22 | import org.eclipse.swt.widgets.Combo; 23 | import org.eclipse.swt.widgets.Composite; 24 | import org.eclipse.swt.widgets.Label; 25 | 26 | /** 27 | * @author Fred Bricon 28 | */ 29 | public class PolyglotTranslaterWizardPage extends WizardPage { 30 | 31 | private boolean addExtension = true; 32 | private File mvnExtensionsDir; 33 | 34 | private Combo languagesCombo; 35 | 36 | public boolean isAddExtension() { 37 | return addExtension; 38 | } 39 | 40 | public File getMvnExtensionsDir() { 41 | return mvnExtensionsDir; 42 | } 43 | 44 | public Language getLanguage() { 45 | return Language.valueOf(languagesCombo.getText()); 46 | } 47 | 48 | protected PolyglotTranslaterWizardPage(IMavenProjectFacade facade) { 49 | super("Translate Project to Polyglot Maven"); 50 | setTitle("Translate "+facade.getProject().getName() + " to Polyglot Maven"); 51 | mvnExtensionsDir = new File(facade.getPomFile().getParentFile(), ".mvn"); 52 | } 53 | 54 | @Override 55 | public void createControl(Composite parent) { 56 | Composite container = new Composite(parent, SWT.NULL); 57 | setControl(container); 58 | container.setLayout(new GridLayout(2, false)); 59 | 60 | Label lblTranslateProjectTo = new Label(container, SWT.NONE); 61 | lblTranslateProjectTo.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); 62 | lblTranslateProjectTo.setText("Translate project pom.xml to"); 63 | 64 | languagesCombo = new Combo(container, SWT.READ_ONLY); 65 | GridData gd_combo = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); 66 | gd_combo.widthHint = 100; 67 | languagesCombo.setLayoutData(gd_combo); 68 | languagesCombo.setItems(getLanguages()); 69 | languagesCombo.setText(Language.groovy.name()); 70 | } 71 | 72 | private String[] getLanguages() { 73 | return Arrays.asList(Language.values()) 74 | .stream() 75 | .map(lang -> lang.name()) 76 | .collect(Collectors.toList()) 77 | .toArray(new String[Language.values().length]); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /org.jboss.tools.maven.polyglot.poc.ui/src/main/java/org/jboss/tools/maven/polyglot/poc/internal/ui/translation/TranslateToPolyglotProjectHandler.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2015 Red Hat, Inc. 3 | * Distributed under license by Red Hat, Inc. All rights reserved. 4 | * This program is made available under the terms of the 5 | * Eclipse Public License v1.0 which accompanies this distribution, 6 | * and is available at http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Red Hat, Inc. - initial API and implementation 10 | ******************************************************************************/ 11 | package org.jboss.tools.maven.polyglot.poc.internal.ui.translation; 12 | 13 | import org.eclipse.core.commands.AbstractHandler; 14 | import org.eclipse.core.commands.ExecutionEvent; 15 | import org.eclipse.core.commands.ExecutionException; 16 | import org.eclipse.core.resources.IProject; 17 | import org.eclipse.core.resources.IResource; 18 | import org.eclipse.core.runtime.IAdaptable; 19 | import org.eclipse.core.runtime.NullProgressMonitor; 20 | import org.eclipse.jface.viewers.ISelection; 21 | import org.eclipse.jface.viewers.IStructuredSelection; 22 | import org.eclipse.jface.wizard.WizardDialog; 23 | import org.eclipse.m2e.core.MavenPlugin; 24 | import org.eclipse.m2e.core.project.IMavenProjectFacade; 25 | import org.eclipse.swt.widgets.Display; 26 | import org.eclipse.swt.widgets.Shell; 27 | import org.eclipse.ui.handlers.HandlerUtil; 28 | 29 | /** 30 | * @author Fred Bricon 31 | */ 32 | public class TranslateToPolyglotProjectHandler extends AbstractHandler { 33 | 34 | @Override 35 | public Object execute(ExecutionEvent event) throws ExecutionException { 36 | final IProject project = getSelectedProject(event); 37 | if (project == null) { 38 | return null; 39 | } 40 | final Shell shell = HandlerUtil.getActiveShell(event); 41 | Display.getDefault().asyncExec(new Runnable() { 42 | 43 | @Override 44 | public void run() { 45 | IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().create(project, new NullProgressMonitor()); 46 | if (facade == null) { 47 | return; 48 | } 49 | PolyglotTranslaterWizard wizard = new PolyglotTranslaterWizard(facade); 50 | WizardDialog wizardDialog = new WizardDialog(shell, wizard); 51 | wizardDialog.setPageSize(150, 100); 52 | wizardDialog.open(); 53 | } 54 | }); 55 | return null; 56 | } 57 | 58 | private IProject getSelectedProject(ExecutionEvent event) { 59 | ISelection currentSelection = HandlerUtil.getCurrentSelection(event); 60 | if (currentSelection instanceof IStructuredSelection) { 61 | Object o = ((IStructuredSelection)currentSelection).getFirstElement(); 62 | if (o instanceof IResource) { 63 | return ((IResource)o).getProject(); 64 | } else if (o instanceof IAdaptable) { 65 | return (IProject)((IAdaptable)o).getAdapter(IProject.class); 66 | } 67 | } 68 | return null; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | org.jboss.tools.maven.polyglot.poc 5 | org.jboss.tools.maven.polyglot.poc 6 | 0.0.1-SNAPSHOT 7 | pom 8 | ${projectName} :: parent 9 | ${projectName} 10 | 11 | 12 | M2E Polyglot Support Experiment 13 | UTF-8 14 | UTF-8 15 | 1.1.0 16 | ${tycho.version} 17 | 18 | -Xmx512m 19 | 20 | 21 | 22 | 23 | oxygen 24 | p2 25 | http://download.eclipse.org/releases/oxygen 26 | 27 | 28 | 29 | 30 | 31 | org.eclipse.tycho 32 | tycho-maven-plugin 33 | ${tycho.version} 34 | true 35 | 36 | 37 | org.eclipse.tycho 38 | target-platform-configuration 39 | ${tycho.version} 40 | 41 | p2 42 | consider 43 | true 44 | 45 | 46 | 47 | org.eclipse.tycho 48 | tycho-source-plugin 49 | ${tycho.version} 50 | 51 | 52 | attach-source 53 | 54 | plugin-source 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | org.eclipse.tycho 65 | tycho-packaging-plugin 66 | ${tycho.version} 67 | 68 | yyyyMMdd-HHmm 69 | 70 | 71 | 72 | org.eclipse.tycho 73 | tycho-surefire-plugin 74 | ${tycho.version} 75 | 76 | true 77 | ${tycho.test.jvmArgs} 78 | 79 | 60 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | macosx 88 | 89 | mac 90 | 91 | 92 | -XstartOnFirstThread 93 | 94 | 95 | 96 | source-feature 97 | 98 | 99 | feature.xml 100 | 101 | 102 | 103 | 104 | 105 | org.eclipse.tycho.extras 106 | tycho-source-feature-plugin 107 | ${tycho.extras.version} 108 | 109 | 110 | source-feature 111 | package 112 | 113 | source-feature 114 | 115 | 116 | 117 | 118 | 119 | org.eclipse.tycho 120 | tycho-p2-plugin 121 | ${tycho.version} 122 | 123 | 124 | attach-p2-metadata 125 | package 126 | 127 | p2-metadata 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | org.jboss.tools.maven.polyglot.poc.core 138 | org.jboss.tools.maven.polyglot.poc.ui 139 | 140 | org.jboss.tools.maven.polyglot.poc.feature 141 | org.jboss.tools.maven.polyglot.poc.site 142 | 143 | 144 | --------------------------------------------------------------------------------