Coverage Report - org.seasar.eclipse.common.launch.LaunchConfigurationFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
LaunchConfigurationFactory
0%
0/20
0%
0/8
0
LaunchConfigurationFactory$CreationHandler
N/A
N/A
0
 
 1  
 /*
 2  
  * Copyright 2004-2008 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.eclipse.common.launch;
 17  
 
 18  
 import org.eclipse.core.runtime.CoreException;
 19  
 import org.eclipse.debug.core.DebugPlugin;
 20  
 import org.eclipse.debug.core.ILaunchConfiguration;
 21  
 import org.eclipse.debug.core.ILaunchConfigurationType;
 22  
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
 23  
 import org.eclipse.debug.core.ILaunchManager;
 24  
 import org.seasar.eclipse.common.CommonPlugin;
 25  
 
 26  
 /**
 27  
  * @author taichi
 28  
  * 
 29  
  */
 30  0
 public class LaunchConfigurationFactory {
 31  
 
 32  
     public static ILaunchConfiguration create(CreationHandler handler) {
 33  0
         ILaunchConfiguration config = null;
 34  
         try {
 35  0
             ILaunchManager manager = DebugPlugin.getDefault()
 36  
                     .getLaunchManager();
 37  0
             ILaunchConfigurationType type = manager
 38  
                     .getLaunchConfigurationType(handler.getTypeName());
 39  0
             ILaunchConfiguration[] configs = manager
 40  
                     .getLaunchConfigurations(type);
 41  0
             for (ILaunchConfiguration element : configs) {
 42  0
                 if (element.getName().equals(handler.getConfigName())) {
 43  0
                     if (handler.equals(element)) {
 44  0
                         config = element;
 45  
                     } else {
 46  0
                         element.delete();
 47  
                     }
 48  0
                     break;
 49  
                 }
 50  
             }
 51  0
             if (config == null) {
 52  0
                 ILaunchConfigurationWorkingCopy copy = type.newInstance(null,
 53  
                         handler.getConfigName());
 54  0
                 handler.setUp(copy);
 55  0
                 config = copy.doSave();
 56  
             }
 57  0
         } catch (CoreException e) {
 58  0
             CommonPlugin.log(e);
 59  0
         }
 60  0
         return config;
 61  
     }
 62  
 
 63  0
     public interface CreationHandler {
 64  
 
 65  
         String getTypeName();
 66  
 
 67  
         String getConfigName();
 68  
 
 69  
         boolean equals(ILaunchConfiguration config);
 70  
 
 71  
         void setUp(ILaunchConfigurationWorkingCopy config);
 72  
     }
 73  
 }