use of org.eclipse.m2e.core.embedder.IMaven in project eclipse.jdt.ls by eclipse.
the class DependencyUtil method getLocalArtifactFile.
// From org.eclipse.m2e.jdt.internal.BuildPathManager#getAttachedArtifactFile
private static File getLocalArtifactFile(ArtifactKey a) {
// can't use Maven resolve methods since they mark artifacts as not-found even if they could be resolved remotely
IMaven maven = MavenPlugin.getMaven();
try {
ArtifactRepository localRepository = maven.getLocalRepository();
String relPath = // $NON-NLS-1$
maven.getArtifactPath(// $NON-NLS-1$
localRepository, // $NON-NLS-1$
a.getGroupId(), // $NON-NLS-1$
a.getArtifactId(), // $NON-NLS-1$
a.getVersion(), // $NON-NLS-1$
"jar", a.getClassifier());
File file = new File(localRepository.getBasedir(), relPath).getCanonicalFile();
if (file.canRead() && file.isFile()) {
return file;
}
} catch (CoreException | IOException ex) {
// fall through
}
return null;
}
use of org.eclipse.m2e.core.embedder.IMaven in project liferay-ide by liferay.
the class MavenModuleProjectTests method testNewLiferayComponentBndAndMavenForPortleActionCommandAndRest.
@Test
public void testNewLiferayComponentBndAndMavenForPortleActionCommandAndRest() throws Exception {
NewLiferayModuleProjectOp pop = NewLiferayModuleProjectOp.TYPE.instantiate();
pop.setProjectName("testMavenModuleComponentBnd");
pop.setProjectTemplateName("portlet");
pop.setProjectProvider("maven-module");
Status modulePorjectStatus = NewLiferayModuleProjectOpMethods.execute(pop, ProgressMonitorBridge.create(new NullProgressMonitor()));
assertTrue(modulePorjectStatus.ok());
IProject modPorject = CoreUtil.getProject(pop.getProjectName().content());
modPorject.open(new NullProgressMonitor());
NewLiferayComponentOp cop = NewLiferayComponentOp.TYPE.instantiate();
cop.setProjectName(pop.getProjectName().content());
cop.setComponentClassTemplateName("PortletActionCommand");
NewLiferayComponentOpMethods.execute(cop, ProgressMonitorBridge.create(new NullProgressMonitor()));
IFile bgd = modPorject.getFile("bnd.bnd");
String bndcontent = FileUtil.readContents(bgd.getLocation().toFile(), true);
String bndConfig = "-includeresource: \\" + System.getProperty("line.separator") + "\t" + "@com.liferay.util.bridges-2.0.0.jar!/com/liferay/util/bridges/freemarker/FreeMarkerPortlet.class,\\" + System.getProperty("line.separator") + "\t" + "@com.liferay.util.taglib-2.0.0.jar!/META-INF/*.tld" + System.getProperty("line.separator");
assertTrue(bndcontent.contains(bndConfig));
IFile pomFile = modPorject.getFile(IMavenConstants.POM_FILE_NAME);
final IMaven maven = MavenPlugin.getMaven();
Model model = maven.readModel(pomFile.getLocation().toFile());
List<Dependency> dependencies = model.getDependencies();
boolean hasDependency = false;
for (Dependency de : dependencies) {
String managementKey = de.getManagementKey();
if (managementKey.equals("com.liferay.portal:com.liferay.util.bridges:jar")) {
hasDependency = true;
break;
}
}
assertTrue(hasDependency);
NewLiferayComponentOp copRest = NewLiferayComponentOp.TYPE.instantiate();
copRest.setProjectName(pop.getProjectName().content());
copRest.setComponentClassTemplateName("RestService");
NewLiferayComponentOpMethods.execute(copRest, ProgressMonitorBridge.create(new NullProgressMonitor()));
bgd = modPorject.getFile("bnd.bnd");
bndcontent = FileUtil.readContents(bgd.getLocation().toFile(), true);
assertTrue(bndcontent.contains(bndConfig));
final String restConfig = "Require-Capability: osgi.contract; filter:=\"(&(osgi.contract=JavaJAXRS)(version=2))\"";
assertTrue(bndcontent.contains(restConfig));
model = maven.readModel(pomFile.getLocation().toFile());
dependencies = model.getDependencies();
hasDependency = false;
for (Dependency de : dependencies) {
String managementKey = de.getManagementKey();
if (managementKey.equals("javax.ws.rs:javax.ws.rs-api:jar")) {
hasDependency = true;
break;
}
}
assertTrue(hasDependency);
NewLiferayComponentOp copAuth = NewLiferayComponentOp.TYPE.instantiate();
copAuth.setProjectName(pop.getProjectName().content());
copAuth.setComponentClassTemplateName("Authenticator");
NewLiferayComponentOpMethods.execute(copAuth, ProgressMonitorBridge.create(new NullProgressMonitor()));
bgd = modPorject.getFile("bnd.bnd");
bndcontent = FileUtil.readContents(bgd.getLocation().toFile(), true);
bndConfig = "-includeresource: \\" + System.getProperty("line.separator") + "\t" + "@com.liferay.util.bridges-2.0.0.jar!/com/liferay/util/bridges/freemarker/FreeMarkerPortlet.class,\\" + System.getProperty("line.separator") + "\t" + "@com.liferay.util.taglib-2.0.0.jar!/META-INF/*.tld,\\" + System.getProperty("line.separator") + "\t" + "@shiro-core-1.1.0.jar";
assertTrue(bndcontent.contains(bndConfig));
model = maven.readModel(pomFile.getLocation().toFile());
dependencies = model.getDependencies();
hasDependency = false;
for (Dependency de : dependencies) {
String managementKey = de.getManagementKey();
if (managementKey.equals("org.apache.shiro:shiro-core:jar")) {
hasDependency = true;
break;
}
}
assertTrue(hasDependency);
}
use of org.eclipse.m2e.core.embedder.IMaven in project liferay-ide by liferay.
the class MavenUtil method executeGoals.
public static IStatus executeGoals(IMavenProjectFacade facade, IMavenExecutionContext context, List<String> goals, IProgressMonitor monitor) throws CoreException {
IMaven maven = MavenPlugin.getMaven();
MavenProject mavenProject = facade.getMavenProject(monitor);
MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, goals, true, monitor);
List<MojoExecution> mojos = plan.getMojoExecutions();
ResolverConfiguration configuration = facade.getResolverConfiguration();
configuration.setResolveWorkspaceProjects(true);
for (MojoExecution mojo : mojos) {
maven.execute(mavenProject, mojo, monitor);
}
return Status.OK_STATUS;
}
use of org.eclipse.m2e.core.embedder.IMaven in project liferay-ide by liferay.
the class MavenUtil method getLocalRepositoryDir.
public static String getLocalRepositoryDir() {
String retval = null;
IMavenConfiguration mavenConfiguration = MavenPlugin.getMavenConfiguration();
String userSettings = mavenConfiguration.getUserSettingsFile();
if ((userSettings == null) || (userSettings.length() == 0)) {
userSettings = SettingsXmlConfigurationProcessor.DEFAULT_USER_SETTINGS_FILE.getAbsolutePath();
}
String globalSettings = MavenPlugin.getMavenConfiguration().getGlobalSettingsFile();
IMaven maven = MavenPlugin.getMaven();
try {
Settings settings = maven.buildSettings(globalSettings, userSettings);
retval = settings.getLocalRepository();
} catch (CoreException ce) {
LiferayMavenCore.logError("Unable to get local repository dir.", ce);
}
if (retval == null) {
retval = org.apache.maven.repository.RepositorySystem.defaultUserLocalRepository.getAbsolutePath();
}
return retval;
}
use of org.eclipse.m2e.core.embedder.IMaven in project liferay-ide by liferay.
the class NewMavenPluginProjectProvider method validateProjectLocation.
@Override
public IStatus validateProjectLocation(String projectName, IPath path) {
IStatus retval = Status.OK_STATUS;
/*
* if the path is a folder and it has a pom.xml that is a package type of 'pom'
* then this is a valid location if projectName is null or empty , don't need to check
* just return
*/
if (CoreUtil.isNullOrEmpty(projectName)) {
return retval;
}
File dir = path.toFile();
if (FileUtil.notExists(dir)) {
return retval;
}
File pomFile = path.append(IMavenConstants.POM_FILE_NAME).toFile();
if (FileUtil.exists(pomFile)) {
IMaven maven = MavenPlugin.getMaven();
try {
Model result = maven.readModel(pomFile);
if (!"pom".equals(result.getPackaging())) {
retval = LiferayMavenCore.createErrorStatus("\"" + pomFile.getParent() + "\" contains a non-parent maven project.");
} else {
String name = result.getName();
if (projectName.equals(name)) {
retval = LiferayMavenCore.createErrorStatus("The project name \"" + projectName + "\" can't be the same as the parent.");
} else {
IPath newProjectPath = path.append(projectName);
retval = validateProjectLocation(projectName, newProjectPath);
}
}
} catch (CoreException ce) {
retval = LiferayMavenCore.createErrorStatus("Invalid project location.", ce);
LiferayMavenCore.log(retval);
}
} else {
File[] files = dir.listFiles();
if (ListUtil.isNotEmpty(files)) {
retval = LiferayMavenCore.createErrorStatus("Project location is not empty or a parent pom.");
}
}
return retval;
}
Aggregations