Exemple #1
0
    @Issue("JENKINS-9367")
    @Test public void persistence() throws Exception {
        ListView view = listView("foo");

        ListView v = (ListView) Jenkins.XSTREAM.fromXML(Jenkins.XSTREAM.toXML(view));
        System.out.println(v.getProperties());
        assertNotNull(v.getProperties());
    }
Exemple #2
0
  /** Updates Job by its XML definition. */
  public void updateByXml(Source source) throws IOException {
    checkPermission(CONFIGURE);
    StringWriter out = new StringWriter();
    try {
      // this allows us to use UTF-8 for storing data,
      // plus it checks any well-formedness issue in the submitted
      // data
      Transformer t = TransformerFactory.newInstance().newTransformer();
      t.transform(source, new StreamResult(out));
      out.close();
    } catch (TransformerException e) {
      throw new IOException("Failed to persist configuration.xml", e);
    }

    // try to reflect the changes by reloading
    InputStream in =
        new BufferedInputStream(new ByteArrayInputStream(out.toString().getBytes("UTF-8")));
    try {
      // Do not allow overwriting view name as it might collide with another
      // view in same ViewGroup and might not satisfy Jenkins.checkGoodName.
      String oldname = name;
      Jenkins.XSTREAM.unmarshal(new XppDriver().createReader(in), this);
      name = oldname;
    } catch (StreamException e) {
      throw new IOException("Unable to read", e);
    } catch (ConversionException e) {
      throw new IOException("Unable to read", e);
    } catch (Error e) { // mostly reflection errors
      throw new IOException("Unable to read", e);
    } finally {
      in.close();
    }
    save();
  }
Exemple #3
0
  private static View copy(StaplerRequest req, ViewGroup owner, String name) throws IOException {
    View v;
    String from = req.getParameter("from");
    View src = src = owner.getView(from);

    if (src == null) {
      if (Util.fixEmpty(from) == null) throw new Failure("Specify which view to copy");
      else throw new Failure("No such view: " + from);
    }
    String xml = Jenkins.XSTREAM.toXML(src);
    v = createViewFromXML(name, new StringInputStream(xml));
    return v;
  }
Exemple #4
0
 public static View createViewFromXML(String name, InputStream xml) throws IOException {
   InputStream in = new BufferedInputStream(xml);
   try {
     View v = (View) Jenkins.XSTREAM.fromXML(in);
     v.name = name;
     return v;
   } catch (StreamException e) {
     throw new IOException2("Unable to read", e);
   } catch (ConversionException e) {
     throw new IOException2("Unable to read", e);
   } catch (Error e) { // mostly reflection errors
     throw new IOException2("Unable to read", e);
   } finally {
     in.close();
   }
 }
 static {
   Jenkins.XSTREAM.alias(
       "org.jenkinsci.plugins.configfiles.maven.DefaultGlobalMavenSettingsProvider",
       GlobalMavenSettingsConfigProvider.class);
 }