refactoring
[walaincubator.git] / com.ibm.wala.eclipse / src / com / ibm / wala / eclipse / headless / HeadlessUtil.java
blob19c7d92924c1077a589cc74e44f88b047c6845d3
1 /*******************************************************************************
2 * Copyright (c) 2007 IBM Corporation.
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
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package com.ibm.wala.eclipse.headless;
13 import java.util.Properties;
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.resources.IWorkspaceRoot;
17 import org.eclipse.core.resources.ResourcesPlugin;
18 import org.eclipse.core.runtime.IPath;
19 import org.eclipse.jdt.core.IJavaProject;
20 import org.eclipse.jdt.core.JavaCore;
21 import org.eclipse.jdt.internal.core.JavaProject;
23 import com.ibm.wala.eclipse.util.EclipseProjectPath;
24 import com.ibm.wala.ipa.callgraph.AnalysisScope;
25 import com.ibm.wala.util.debug.Assertions;
26 import com.ibm.wala.util.io.CommandLine;
27 import com.ibm.wala.util.warnings.WalaException;
29 public class HeadlessUtil {
31 /**
32 * create a Properties object representing the properties set by the command
33 * line args. if args[i] is "-foo" and args[i+1] is "bar", then the result
34 * will define a property with key "foo" and value "bar"
36 * @throws WalaException
38 public static Properties parseCommandLine(String[] cmdLine) {
39 Properties p = null;
40 assert cmdLine[0].equals("-pdelaunch");
41 String[] x = new String[cmdLine.length - 1];
42 System.arraycopy(cmdLine, 1, x, 0, x.length);
43 try {
44 p = CommandLine.parse(x);
45 } catch (WalaException e) {
46 e.printStackTrace();
47 System.err.println("Length " + x.length);
48 for (String s : x) {
49 System.err.println(s);
51 Assertions.UNREACHABLE();
53 return p;
56 /**
57 * compute the analysis scope for a project in the current workspace
59 public static AnalysisScope computeScope(String projectName) {
60 IJavaProject jp = getProjectFromWorkspace(projectName);
61 IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
62 EclipseProjectPath path = EclipseProjectPath.make(workspaceRoot.getLocation(), jp);
63 return path.toAnalysisScope(null);
66 @SuppressWarnings("restriction")
67 private static IJavaProject getProjectFromWorkspace(String projectName) {
68 IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
69 IPath workspaceRootPath = workspaceRoot.getLocation();
70 System.out.println("workspace: " + workspaceRootPath.toOSString());
72 for (IProject p : workspaceRoot.getProjects()) {
73 if (JavaProject.hasJavaNature(p)) {
74 IJavaProject jp = JavaCore.create(p);
75 if (jp != null && jp.getElementName().equals(projectName)) {
76 return jp;
80 Assertions.UNREACHABLE();
81 return null;